Command.c 531 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789
  1. // SoftEther VPN Source Code
  2. // Cedar Communication Module
  3. //
  4. // SoftEther VPN Server, Client and Bridge are free software under GPLv2.
  5. //
  6. // Copyright (c) 2012-2015 Daiyuu Nobori.
  7. // Copyright (c) 2012-2015 SoftEther VPN Project, University of Tsukuba, Japan.
  8. // Copyright (c) 2012-2015 SoftEther Corporation.
  9. //
  10. // All Rights Reserved.
  11. //
  12. // http://www.softether.org/
  13. //
  14. // Author: Daiyuu Nobori
  15. // Comments: Tetsuo Sugiyama, Ph.D.
  16. //
  17. // This program is free software; you can redistribute it and/or
  18. // modify it under the terms of the GNU General Public License
  19. // version 2 as published by the Free Software Foundation.
  20. //
  21. // This program is distributed in the hope that it will be useful,
  22. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. // GNU General Public License for more details.
  25. //
  26. // You should have received a copy of the GNU General Public License version 2
  27. // along with this program; if not, write to the Free Software
  28. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  29. //
  30. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  31. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  32. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  33. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  34. // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  35. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  36. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  37. //
  38. // THE LICENSE AGREEMENT IS ATTACHED ON THE SOURCE-CODE PACKAGE
  39. // AS "LICENSE.TXT" FILE. READ THE TEXT FILE IN ADVANCE TO USE THE SOFTWARE.
  40. //
  41. //
  42. // THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN,
  43. // UNDER JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY,
  44. // MERGE, PUBLISH, DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS
  45. // SOFTWARE, THAT ANY JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS
  46. // SOFTWARE OR ITS CONTENTS, AGAINST US (SOFTETHER PROJECT, SOFTETHER
  47. // CORPORATION, DAIYUU NOBORI OR OTHER SUPPLIERS), OR ANY JURIDICAL
  48. // DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND OF USING, COPYING,
  49. // MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING, AND/OR
  50. // SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND
  51. // CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO
  52. // EXCLUSIVE JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO,
  53. // JAPAN. YOU MUST WAIVE ALL DEFENSES OF LACK OF PERSONAL JURISDICTION
  54. // AND FORUM NON CONVENIENS. PROCESS MAY BE SERVED ON EITHER PARTY IN
  55. // THE MANNER AUTHORIZED BY APPLICABLE LAW OR COURT RULE.
  56. //
  57. // USE ONLY IN JAPAN. DO NOT USE THIS SOFTWARE IN ANOTHER COUNTRY UNLESS
  58. // YOU HAVE A CONFIRMATION THAT THIS SOFTWARE DOES NOT VIOLATE ANY
  59. // CRIMINAL LAWS OR CIVIL RIGHTS IN THAT PARTICULAR COUNTRY. USING THIS
  60. // SOFTWARE IN OTHER COUNTRIES IS COMPLETELY AT YOUR OWN RISK. THE
  61. // SOFTETHER VPN PROJECT HAS DEVELOPED AND DISTRIBUTED THIS SOFTWARE TO
  62. // COMPLY ONLY WITH THE JAPANESE LAWS AND EXISTING CIVIL RIGHTS INCLUDING
  63. // PATENTS WHICH ARE SUBJECTS APPLY IN JAPAN. OTHER COUNTRIES' LAWS OR
  64. // CIVIL RIGHTS ARE NONE OF OUR CONCERNS NOR RESPONSIBILITIES. WE HAVE
  65. // NEVER INVESTIGATED ANY CRIMINAL REGULATIONS, CIVIL LAWS OR
  66. // INTELLECTUAL PROPERTY RIGHTS INCLUDING PATENTS IN ANY OF OTHER 200+
  67. // COUNTRIES AND TERRITORIES. BY NATURE, THERE ARE 200+ REGIONS IN THE
  68. // WORLD, WITH DIFFERENT LAWS. IT IS IMPOSSIBLE TO VERIFY EVERY
  69. // COUNTRIES' LAWS, REGULATIONS AND CIVIL RIGHTS TO MAKE THE SOFTWARE
  70. // COMPLY WITH ALL COUNTRIES' LAWS BY THE PROJECT. EVEN IF YOU WILL BE
  71. // SUED BY A PRIVATE ENTITY OR BE DAMAGED BY A PUBLIC SERVANT IN YOUR
  72. // COUNTRY, THE DEVELOPERS OF THIS SOFTWARE WILL NEVER BE LIABLE TO
  73. // RECOVER OR COMPENSATE SUCH DAMAGES, CRIMINAL OR CIVIL
  74. // RESPONSIBILITIES. NOTE THAT THIS LINE IS NOT LICENSE RESTRICTION BUT
  75. // JUST A STATEMENT FOR WARNING AND DISCLAIMER.
  76. //
  77. //
  78. // SOURCE CODE CONTRIBUTION
  79. // ------------------------
  80. //
  81. // Your contribution to SoftEther VPN Project is much appreciated.
  82. // Please send patches to us through GitHub.
  83. // Read the SoftEther VPN Patch Acceptance Policy in advance:
  84. // http://www.softether.org/5-download/src/9.patch
  85. //
  86. //
  87. // DEAR SECURITY EXPERTS
  88. // ---------------------
  89. //
  90. // If you find a bug or a security vulnerability please kindly inform us
  91. // about the problem immediately so that we can fix the security problem
  92. // to protect a lot of users around the world as soon as possible.
  93. //
  94. // Our e-mail address for security reports is:
  95. // softether-vpn-security [at] softether.org
  96. //
  97. // Please note that the above e-mail address is not a technical support
  98. // inquiry address. If you need technical assistance, please visit
  99. // http://www.softether.org/ and ask your question on the users forum.
  100. //
  101. // Thank you for your cooperation.
  102. //
  103. //
  104. // NO MEMORY OR RESOURCE LEAKS
  105. // ---------------------------
  106. //
  107. // The memory-leaks and resource-leaks verification under the stress
  108. // test has been passed before release this source code.
  109. // Command.c
  110. // vpncmd Command Line Management Utility
  111. #include "CedarPch.h"
  112. // System checker definition
  113. typedef bool (CHECKER_PROC_DEF)();
  114. typedef struct CHECKER_PROC
  115. {
  116. char *Title;
  117. CHECKER_PROC_DEF *Proc;
  118. } CHECKER_PROC;
  119. static CHECKER_PROC checker_procs[] =
  120. {
  121. {"CHECK_PROC_KERNEL", CheckKernel},
  122. {"CHECK_PROC_MEMORY", CheckMemory},
  123. {"CHECK_PROC_STRINGS", CheckStrings},
  124. {"CHECK_PROC_FILESYSTEM", CheckFileSystem},
  125. {"CHECK_PROC_THREAD", CheckThread},
  126. {"CHECK_PROC_NETWORK", CheckNetwork},
  127. };
  128. typedef struct CHECK_NETWORK_1
  129. {
  130. SOCK *ListenSocket;
  131. } CHECK_NETWORK_1;
  132. typedef struct CHECK_NETWORK_2
  133. {
  134. SOCK *s;
  135. X *x;
  136. K *k;
  137. } CHECK_NETWORK_2;
  138. // Convert the TT_RESULT to RPC
  139. void OutRpcTtResult(PACK *p, TT_RESULT *t)
  140. {
  141. if (p == NULL || t == NULL)
  142. {
  143. return;
  144. }
  145. PackAddBool(p, "Raw", t->Raw);
  146. PackAddBool(p, "Double", t->Double);
  147. PackAddInt64(p, "NumBytesUpload", t->NumBytesUpload);
  148. PackAddInt64(p, "NumBytesDownload", t->NumBytesDownload);
  149. PackAddInt64(p, "NumBytesTotal", t->NumBytesTotal);
  150. PackAddInt64(p, "Span", t->Span);
  151. PackAddInt64(p, "BpsUpload", t->BpsUpload);
  152. PackAddInt64(p, "BpsDownload", t->BpsDownload);
  153. PackAddInt64(p, "BpsTotal", t->BpsTotal);
  154. }
  155. // Convert an RPC to a TT_RESULT
  156. void InRpcTtResult(PACK *p, TT_RESULT *t)
  157. {
  158. if (p == NULL || t == NULL)
  159. {
  160. return;
  161. }
  162. Zero(t, sizeof(TT_RESULT));
  163. t->Raw = PackGetBool(p, "Raw");
  164. t->Double = PackGetBool(p, "Double");
  165. t->NumBytesUpload = PackGetInt64(p, "NumBytesUpload");
  166. t->NumBytesDownload = PackGetInt64(p, "NumBytesDownload");
  167. t->NumBytesTotal = PackGetInt64(p, "NumBytesTotal");
  168. t->Span = PackGetInt64(p, "Span");
  169. t->BpsUpload = PackGetInt64(p, "BpsUpload");
  170. t->BpsDownload = PackGetInt64(p, "BpsDownload");
  171. t->BpsTotal = PackGetInt64(p, "BpsTotal");
  172. }
  173. // Accept thread
  174. void CheckNetworkAcceptThread(THREAD *thread, void *param)
  175. {
  176. CHECK_NETWORK_2 *c = (CHECK_NETWORK_2 *)param;
  177. SOCK *s = c->s;
  178. UINT i = 0;
  179. if (StartSSL(s, c->x, c->k))
  180. {
  181. while (true)
  182. {
  183. i++;
  184. if (Send(s, &i, sizeof(UINT), true) == 0)
  185. {
  186. break;
  187. }
  188. }
  189. }
  190. Disconnect(s);
  191. ReleaseSock(s);
  192. }
  193. // Listen thread
  194. void CheckNetworkListenThread(THREAD *thread, void *param)
  195. {
  196. CHECK_NETWORK_1 *c = (CHECK_NETWORK_1 *)param;
  197. SOCK *s;
  198. UINT i;
  199. K *pub, *pri;
  200. X *x;
  201. LIST *o = NewList(NULL);
  202. NAME *name = NewName(L"Test", L"Test", L"Test", L"JP", L"Ibaraki", L"Tsukuba");
  203. RsaGen(&pri, &pub, 1024);
  204. x = NewRootX(pub, pri, name, 1000, NULL);
  205. FreeName(name);
  206. for (i = 1025;;i++)
  207. {
  208. s = Listen(i);
  209. if (s != NULL)
  210. {
  211. break;
  212. }
  213. }
  214. c->ListenSocket = s;
  215. AddRef(s->ref);
  216. NoticeThreadInit(thread);
  217. while (true)
  218. {
  219. SOCK *new_sock = Accept(s);
  220. if (new_sock == NULL)
  221. {
  222. break;
  223. }
  224. else
  225. {
  226. CHECK_NETWORK_2 c;
  227. THREAD *t;
  228. Zero(&c, sizeof(c));
  229. c.s = new_sock;
  230. c.k = pri;
  231. c.x = x;
  232. t = NewThread(CheckNetworkAcceptThread, &c);
  233. Insert(o, t);
  234. }
  235. }
  236. for (i = 0;i < LIST_NUM(o);i++)
  237. {
  238. THREAD *t = LIST_DATA(o, i);
  239. WaitThread(t, INFINITE);
  240. ReleaseThread(t);
  241. }
  242. FreeK(pri);
  243. FreeK(pub);
  244. FreeX(x);
  245. ReleaseSock(s);
  246. ReleaseList(o);
  247. }
  248. // Network function check
  249. bool CheckNetwork()
  250. {
  251. CHECK_NETWORK_1 c;
  252. THREAD *t;
  253. SOCK *listen_socket;
  254. UINT port;
  255. UINT i, num;
  256. bool ok = true;
  257. SOCK **socks;
  258. SOCK_EVENT *se = NewSockEvent();
  259. Zero(&c, sizeof(c));
  260. t = NewThread(CheckNetworkListenThread, &c);
  261. WaitThreadInit(t);
  262. listen_socket = c.ListenSocket;
  263. port = listen_socket->LocalPort;
  264. num = 8;
  265. socks = ZeroMalloc(sizeof(SOCK *) * num);
  266. for (i = 0;i < num;i++)
  267. {
  268. socks[i] = Connect("localhost", port);
  269. if (socks[i] == NULL)
  270. {
  271. Print("Connect Failed. (%u)\n", i);
  272. ok = false;
  273. num = i;
  274. break;
  275. }
  276. if (StartSSL(socks[i], NULL, NULL) == false)
  277. {
  278. ReleaseSock(socks[i]);
  279. Print("Connect Failed. (%u)\n", i);
  280. ok = false;
  281. num = i;
  282. break;
  283. }
  284. JoinSockToSockEvent(socks[i], se);
  285. }
  286. if (ok)
  287. {
  288. while (true)
  289. {
  290. UINT i;
  291. bool end = false;
  292. bool all_blocked = true;
  293. for (i = 0;i < num;i++)
  294. {
  295. UINT n;
  296. UINT ret;
  297. n = 0;
  298. ret = Recv(socks[i], &n, sizeof(UINT), true);
  299. if (ret == 0)
  300. {
  301. Print("Recv Failed (Disconnected).\n", ret);
  302. end = true;
  303. ok = false;
  304. }
  305. if (ret != SOCK_LATER)
  306. {
  307. all_blocked = false;
  308. }
  309. if (n >= 128)
  310. {
  311. end = true;
  312. }
  313. }
  314. if (end)
  315. {
  316. break;
  317. }
  318. if (all_blocked)
  319. {
  320. WaitSockEvent(se, INFINITE);
  321. }
  322. }
  323. }
  324. for (i = 0;i < num;i++)
  325. {
  326. Disconnect(socks[i]);
  327. ReleaseSock(socks[i]);
  328. }
  329. Free(socks);
  330. Disconnect(listen_socket);
  331. WaitThread(t, INFINITE);
  332. ReleaseThread(t);
  333. ReleaseSock(listen_socket);
  334. ReleaseSockEvent(se);
  335. return ok;
  336. }
  337. typedef struct CHECK_THREAD_1
  338. {
  339. UINT num;
  340. LOCK *lock;
  341. THREAD *wait_thread;
  342. } CHECK_THREAD_1;
  343. static UINT check_thread_global_1 = 0;
  344. #define CHECK_THREAD_INCREMENT_COUNT 32
  345. // Test thread 1
  346. void CheckThread1(THREAD *thread, void *param)
  347. {
  348. CHECK_THREAD_1 *ct1 = (CHECK_THREAD_1 *)param;
  349. UINT i;
  350. UINT num = CHECK_THREAD_INCREMENT_COUNT;
  351. WaitThread(ct1->wait_thread, INFINITE);
  352. for (i = 0;i < num;i++)
  353. {
  354. Lock(ct1->lock);
  355. check_thread_global_1 = ct1->num;
  356. InputToNull((void *)check_thread_global_1);
  357. check_thread_global_1 = check_thread_global_1 + 1 + RetZero();
  358. ct1->num = check_thread_global_1;
  359. Unlock(ct1->lock);
  360. }
  361. }
  362. // Test thread 2
  363. void CheckThread2(THREAD *thread, void *param)
  364. {
  365. EVENT *e = (EVENT *)param;
  366. Wait(e, INFINITE);
  367. }
  368. typedef struct CHECK_THREAD_3
  369. {
  370. UINT num, a;
  371. } CHECK_THREAD_3;
  372. // Test thread 3
  373. void CheckThread3(THREAD *thread, void *param)
  374. {
  375. CHECK_THREAD_3 *c = (CHECK_THREAD_3 *)param;
  376. THREAD *t;
  377. if (c->num == 0)
  378. {
  379. return;
  380. }
  381. c->num--;
  382. c->a++;
  383. t = NewThread(CheckThread3, c);
  384. WaitThread(t, INFINITE);
  385. ReleaseThread(t);
  386. }
  387. // Thread check
  388. bool CheckThread()
  389. {
  390. bool ok = true;
  391. CHECK_THREAD_1 ct1;
  392. UINT num = 32;
  393. UINT i;
  394. THREAD **threads;
  395. EVENT *e;
  396. THREAD *t2;
  397. THREAD *t;
  398. CHECK_THREAD_3 c;
  399. e = NewEvent();
  400. Zero(&ct1, sizeof(ct1));
  401. ct1.lock = NewLock();
  402. t2 = NewThread(CheckThread2, e);
  403. ct1.wait_thread = t2;
  404. threads = ZeroMalloc(sizeof(THREAD *) * num);
  405. for (i = 0;i < num;i++)
  406. {
  407. threads[i] = NewThread(CheckThread1, &ct1);
  408. if (threads[i] == NULL)
  409. {
  410. Print("Thread %u Create Failed.\n", i);
  411. ok = false;
  412. }
  413. }
  414. Set(e);
  415. for (i = 0;i < num;i++)
  416. {
  417. WaitThread(threads[i], INFINITE);
  418. ReleaseThread(threads[i]);
  419. }
  420. Free(threads);
  421. if (ct1.num != (num * CHECK_THREAD_INCREMENT_COUNT))
  422. {
  423. Print("Threading: %u != %u\n", ct1.num, num * CHECK_THREAD_INCREMENT_COUNT);
  424. ok = false;
  425. }
  426. DeleteLock(ct1.lock);
  427. WaitThread(t2, INFINITE);
  428. ReleaseThread(t2);
  429. ReleaseEvent(e);
  430. num = 32;
  431. Zero(&c, sizeof(c));
  432. c.num = num;
  433. t = NewThread(CheckThread3, &c);
  434. WaitThread(t, INFINITE);
  435. ReleaseThread(t);
  436. if (c.a != num)
  437. {
  438. Print("Threading: %u != %u\n", c.a, num);
  439. ok = false;
  440. }
  441. return ok;
  442. }
  443. // File system check
  444. bool CheckFileSystem()
  445. {
  446. bool ok = true;
  447. char exe[MAX_PATH];
  448. char exe_dir[MAX_PATH];
  449. DIRLIST *dirs;
  450. UINT i;
  451. GetExeName(exe, sizeof(exe));
  452. GetExeDir(exe_dir, sizeof(exe_dir));
  453. ok = false;
  454. dirs = EnumDir(exe_dir);
  455. for (i = 0;i < dirs->NumFiles;i++)
  456. {
  457. if (EndWith(exe, dirs->File[i]->FileName))
  458. {
  459. ok = true;
  460. break;
  461. }
  462. }
  463. FreeDir(dirs);
  464. if (ok == false)
  465. {
  466. Print("EnumDir Failed.\n");
  467. return false;
  468. }
  469. else
  470. {
  471. UINT size = 1234567;
  472. UCHAR *buf;
  473. IO *io;
  474. #ifndef OS_WIN32
  475. wchar_t *filename = L"/tmp/vpn_checker_tmp";
  476. #else // OS_WIN32
  477. wchar_t filename[MAX_PATH];
  478. CombinePathW(filename, sizeof(filename), MsGetMyTempDirW(), L"vpn_checker_tmp");
  479. #endif // OS_WIN32
  480. buf = Malloc(size);
  481. for (i = 0;i < size;i++)
  482. {
  483. buf[i] = i % 256;
  484. }
  485. io = FileCreateW(filename);
  486. if (io == NULL)
  487. {
  488. Print("FileCreate Failed.\n");
  489. Free(buf);
  490. return false;
  491. }
  492. else
  493. {
  494. FileWrite(io, buf, size);
  495. Free(buf);
  496. FileClose(io);
  497. io = FileOpenW(filename, false);
  498. if (FileSize(io) != 1234567)
  499. {
  500. Print("FileSize Failed.\n");
  501. FileClose(io);
  502. return false;
  503. }
  504. else
  505. {
  506. BUF *b;
  507. FileClose(io);
  508. b = ReadDumpW(filename);
  509. for (i = 0;i < b->Size;i++)
  510. {
  511. UCHAR c = ((UCHAR *)b->Buf)[i];
  512. if (c != (i % 256))
  513. {
  514. Print("FileToBuf Failed.\n");
  515. FreeBuf(b);
  516. return false;
  517. }
  518. }
  519. FreeBuf(b);
  520. }
  521. }
  522. FileDeleteW(filename);
  523. }
  524. return ok;
  525. }
  526. // String check
  527. bool CheckStrings()
  528. {
  529. wchar_t *numstr = _UU("CHECK_TEST_123456789");
  530. char tmp[MAX_SIZE];
  531. wchar_t tmp2[MAX_SIZE];
  532. UINT i;
  533. UINT sum, sum2;
  534. UNI_TOKEN_LIST *t;
  535. UniStrCpy(tmp2, sizeof(tmp2), L"");
  536. sum2 = 0;
  537. for (i = 0;i < 64;i++)
  538. {
  539. sum2 += i;
  540. UniFormat(tmp2, sizeof(tmp2), L"%s,%u", tmp2, i);
  541. }
  542. t = UniParseToken(tmp2, L",");
  543. sum = 0;
  544. for (i = 0;i < t->NumTokens;i++)
  545. {
  546. wchar_t *s = t->Token[i];
  547. UINT n = UniToInt(s);
  548. sum += n;
  549. }
  550. UniFreeToken(t);
  551. if (sum != sum2)
  552. {
  553. Print("UniParseToken Failed.\n");
  554. return false;
  555. }
  556. if (UniToInt(numstr) != 123456789)
  557. {
  558. Print("UniToInt Failed.\n");
  559. return false;
  560. }
  561. UniToStr(tmp, sizeof(tmp), numstr);
  562. if (ToInt(tmp) != 123456789)
  563. {
  564. Print("UniToStr Failed.\n");
  565. return false;
  566. }
  567. return true;
  568. }
  569. // Memory check
  570. bool CheckMemory()
  571. {
  572. UINT i, num, size, j;
  573. void **pp;
  574. bool ok = true;
  575. UINT old_size;
  576. num = 2000;
  577. size = 1000;
  578. pp = ZeroMalloc(sizeof(void *) * num);
  579. for (i = 0;i < num;i++)
  580. {
  581. pp[i] = ZeroMalloc(size);
  582. InputToNull(pp[i]);
  583. for (j = 0;j < size;j++)
  584. {
  585. ((UCHAR *)pp[i])[j] = j % 256;
  586. }
  587. }
  588. old_size = size;
  589. size = size * 3;
  590. for (i = 0;i < num;i++)
  591. {
  592. pp[i] = ReAlloc(pp[i], size);
  593. for (j = old_size;j < size;j++)
  594. {
  595. InputToNull((void *)(UINT)(((UCHAR *)pp[i])[j] = j % 256));
  596. }
  597. }
  598. for (i = 0;i < num;i++)
  599. {
  600. for (j = 0;j < size;j++)
  601. {
  602. if (((UCHAR *)pp[i])[j] != (j % 256))
  603. {
  604. ok = false;
  605. }
  606. }
  607. Free(pp[i]);
  608. }
  609. Free(pp);
  610. return ok;
  611. }
  612. // Function that do not do anything
  613. void InputToNull(void *p)
  614. {
  615. if (RetZero() == 1)
  616. {
  617. UCHAR *c = (UCHAR *)p;
  618. c[0] = 0x32;
  619. }
  620. }
  621. // Function that returns 0
  622. UINT RetZero()
  623. {
  624. if (g_debug == 0x123455)
  625. {
  626. return 1;
  627. }
  628. else
  629. {
  630. return 0;
  631. }
  632. }
  633. // Kernel check
  634. bool CheckKernel()
  635. {
  636. UINT num = 10, i;
  637. UINT64 s = Tick64();
  638. UINT64 t = Tick64();
  639. for (i = 0;i < num;i++)
  640. {
  641. UINT64 q = Tick64();
  642. if (t > q)
  643. {
  644. Print("Tick64 #1 Failed.\n");
  645. return false;
  646. }
  647. t = q;
  648. SleepThread(100);
  649. }
  650. t = (Tick64() - s);
  651. if (t <= 500 || t >= 2000)
  652. {
  653. Print("Tick64 #2 Failed.\n");
  654. return false;
  655. }
  656. else if (false)
  657. {
  658. UINT64 tick1 = Tick64();
  659. UINT64 time1;
  660. UINT64 tick2, time2;
  661. SleepThread(1000);
  662. tick2 = Tick64();
  663. time2 = LocalTime64();
  664. time1 = SystemToLocal64(TickToTime(tick1));
  665. if (time2 > time1)
  666. {
  667. s = time2 - time1;
  668. }
  669. else
  670. {
  671. s = time1 - time2;
  672. }
  673. if (s <= 500 || s >= 2000)
  674. {
  675. Print("TickToTime Failed.\n");
  676. return false;
  677. }
  678. }
  679. #ifdef OS_UNIX
  680. {
  681. // Test of child process
  682. UINT pid;
  683. char exe[MAX_SIZE];
  684. GetExeName(exe, sizeof(exe));
  685. pid = fork();
  686. if (pid == -1)
  687. {
  688. Print("fork Failed.\n");
  689. return false;
  690. }
  691. if (pid == 0)
  692. {
  693. char *param = UNIX_ARG_EXIT;
  694. char **args;
  695. args = ZeroMalloc(sizeof(char *) * 3);
  696. args[0] = exe;
  697. args[1] = param;
  698. args[2] = NULL;
  699. setsid();
  700. // Close the standard I/O
  701. UnixCloseIO();
  702. // Stop unwanted signals
  703. signal(SIGHUP, SIG_IGN);
  704. execvp(exe, args);
  705. AbortExit();
  706. }
  707. else
  708. {
  709. int status = 0, ret;
  710. // Wait for the termination of the child process
  711. ret = waitpid(pid, &status, 0);
  712. if (WIFEXITED(status) == 0)
  713. {
  714. // Aborted
  715. Print("waitpid Failed: 0x%x\n", ret);
  716. return false;
  717. }
  718. }
  719. }
  720. #endif // OS_UNIX
  721. return true;
  722. }
  723. // System checker
  724. bool SystemCheck()
  725. {
  726. UINT i;
  727. bool ng = false;
  728. UniPrint(_UU("CHECK_TITLE"));
  729. UniPrint(_UU("CHECK_NOTE"));
  730. for (i = 0;i < sizeof(checker_procs) / sizeof(checker_procs[0]);i++)
  731. {
  732. wchar_t *title;
  733. bool ret = false;
  734. CHECKER_PROC *p = &checker_procs[i];
  735. title = _UU(p->Title);
  736. UniPrint(_UU("CHECK_EXEC_TAG"), title);
  737. ret = p->Proc();
  738. if (ret == false)
  739. {
  740. ng = true;
  741. }
  742. UniPrint(L" %s\n", ret ? _UU("CHECK_PASS") : _UU("CHECK_FAIL"));
  743. }
  744. UniPrint(L"\n");
  745. if (ng == false)
  746. {
  747. UniPrint(L"%s\n\n", _UU("CHECK_RESULT_1"));
  748. }
  749. else
  750. {
  751. UniPrint(L"%s\n\n", _UU("CHECK_RESULT_2"));
  752. }
  753. return true;
  754. }
  755. // Behavior checker
  756. UINT PtCheck(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  757. {
  758. LIST *o;
  759. UINT ret = ERR_NO_ERROR;
  760. // Get the parameter list
  761. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  762. if (o == NULL)
  763. {
  764. return ERR_INVALID_PARAMETER;
  765. }
  766. if (SystemCheck() == false)
  767. {
  768. ret = ERR_INTERNAL_ERROR;
  769. }
  770. FreeParamValueList(o);
  771. return ret;
  772. }
  773. // VPN Tools main function
  774. void PtMain(PT *pt)
  775. {
  776. char prompt[MAX_SIZE];
  777. wchar_t tmp[MAX_SIZE];
  778. // Validate arguments
  779. if (pt == NULL)
  780. {
  781. return;
  782. }
  783. // Display a message that start-up is complete
  784. UniFormat(tmp, sizeof(tmp), _UU("CMD_VPNCMD_TOOLS_CONNECTED"));
  785. pt->Console->Write(pt->Console, tmp);
  786. pt->Console->Write(pt->Console, L"");
  787. while (true)
  788. {
  789. // Definition of command
  790. CMD cmd[] =
  791. {
  792. {"About", PsAbout},
  793. {"MakeCert", PtMakeCert},
  794. {"MakeCert2048", PtMakeCert2048},
  795. {"TrafficClient", PtTrafficClient},
  796. {"TrafficServer", PtTrafficServer},
  797. {"Check", PtCheck},
  798. };
  799. // Generate a prompt
  800. StrCpy(prompt, sizeof(prompt), "VPN Tools>");
  801. if (DispatchNextCmdEx(pt->Console, pt->CmdLine, prompt, cmd, sizeof(cmd) / sizeof(cmd[0]), pt) == false)
  802. {
  803. break;
  804. }
  805. pt->LastError = pt->Console->RetCode;
  806. if (pt->LastError == ERR_NO_ERROR && pt->Console->ConsoleType != CONSOLE_CSV)
  807. {
  808. pt->Console->Write(pt->Console, _UU("CMD_MSG_OK"));
  809. pt->Console->Write(pt->Console, L"");
  810. }
  811. if (pt->CmdLine != NULL)
  812. {
  813. break;
  814. }
  815. }
  816. }
  817. // Create a VPN Tools context
  818. PT *NewPt(CONSOLE *c, wchar_t *cmdline)
  819. {
  820. PT *pt;
  821. // Validate arguments
  822. if (c == NULL)
  823. {
  824. return NULL;
  825. }
  826. if (UniIsEmptyStr(cmdline))
  827. {
  828. cmdline = NULL;
  829. }
  830. pt = ZeroMalloc(sizeof(PT));
  831. pt->Console = c;
  832. pt->CmdLine = CopyUniStr(cmdline);
  833. return pt;
  834. }
  835. // Release the VPN Tools context
  836. void FreePt(PT *pt)
  837. {
  838. // Validate arguments
  839. if (pt == NULL)
  840. {
  841. return;
  842. }
  843. Free(pt->CmdLine);
  844. Free(pt);
  845. }
  846. // Start VPN Tools
  847. UINT PtConnect(CONSOLE *c, wchar_t *cmdline)
  848. {
  849. PT *pt;
  850. UINT ret = 0;
  851. // Validate arguments
  852. if (c == NULL)
  853. {
  854. return ERR_INTERNAL_ERROR;
  855. }
  856. pt = NewPt(c, cmdline);
  857. PtMain(pt);
  858. ret = pt->LastError;
  859. FreePt(pt);
  860. return ret;
  861. }
  862. // Initialize the execution path information of vpncmd command
  863. void VpnCmdInitBootPath()
  864. {
  865. #ifdef OS_WIN32
  866. char exe_path[MAX_PATH];
  867. char tmp[MAX_PATH];
  868. GetExeName(exe_path, sizeof(exe_path));
  869. if (SearchStrEx(exe_path, "ham.exe", 0, false) != INFINITE || SearchStrEx(exe_path, "ham_x64.exe", 0, false) != INFINITE || SearchStrEx(exe_path, "ham_ia64.exe", 0, false) != INFINITE)
  870. {
  871. return;
  872. }
  873. if (MsIsAdmin())
  874. {
  875. UINT current_ver;
  876. // Get the version of vpncmd that is currently installed
  877. current_ver = MsRegReadInt(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_VER);
  878. if ((CEDAR_BUILD >= current_ver) ||
  879. MsRegIsValue(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH) == false)
  880. {
  881. char *src_filename;
  882. bool b = false;
  883. // Copy the vpncmdsys.exe to system32
  884. if (MsIsNt())
  885. {
  886. Format(tmp, sizeof(tmp), "%s\\vpncmd.exe", MsGetSystem32Dir());
  887. }
  888. else
  889. {
  890. Format(tmp, sizeof(tmp), "%s\\vpncmd.exe", MsGetWindowsDir());
  891. }
  892. src_filename = VPNCMD_BOOTSTRAP_FILENAME;
  893. if (IsX64())
  894. {
  895. src_filename = VPNCMD_BOOTSTRAP_FILENAME_X64;
  896. }
  897. if (IsIA64())
  898. {
  899. src_filename = VPNCMD_BOOTSTRAP_FILENAME_IA64;
  900. }
  901. b = true;
  902. if (MsIs64BitWindows() == false || Is64())
  903. {
  904. if (IsFile(tmp) == false || (CEDAR_BUILD > current_ver) || MsRegIsValue(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH) == false)
  905. {
  906. b = FileCopy(src_filename, tmp);
  907. }
  908. }
  909. else
  910. {
  911. void *wow;
  912. wow = MsDisableWow64FileSystemRedirection();
  913. if (true)
  914. {
  915. if (IsFile(tmp) == false || (CEDAR_BUILD > current_ver) || MsRegIsValue(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH) == false)
  916. {
  917. b = FileCopy(src_filename, tmp);
  918. }
  919. }
  920. MsRestoreWow64FileSystemRedirection(wow);
  921. if (true)
  922. {
  923. if (IsFile(tmp) == false || (CEDAR_BUILD > current_ver) || MsRegIsValue(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH) == false)
  924. {
  925. b = FileCopy(src_filename, tmp);
  926. }
  927. }
  928. }
  929. // Because the currently running prompt is newer version, overwrite the registry
  930. if (MsIs64BitWindows() == false)
  931. {
  932. MsRegWriteStr(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH, exe_path);
  933. MsRegWriteInt(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_VER, CEDAR_BUILD);
  934. }
  935. else
  936. {
  937. MsRegWriteStrEx2(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH, exe_path, true, false);
  938. MsRegWriteIntEx2(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_VER, CEDAR_BUILD, true, false);
  939. MsRegWriteStrEx2(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_PATH, exe_path, false, true);
  940. MsRegWriteIntEx2(REG_LOCAL_MACHINE, VPNCMD_BOOTSTRAP_REG_KEYNAME, VPNCMD_BOOTSTRAP_REG_VALUENAME_VER, CEDAR_BUILD, false, true);
  941. }
  942. }
  943. }
  944. #endif // OS_WIN32
  945. }
  946. // Show the string
  947. void TtPrint(void *param, TT_PRINT_PROC *print_proc, wchar_t *str)
  948. {
  949. // Validate arguments
  950. if (print_proc == NULL || str == NULL)
  951. {
  952. return;
  953. }
  954. print_proc(param, str);
  955. }
  956. // Generate new random data
  957. void TtGenerateRandomData(UCHAR **buf, UINT *size)
  958. {
  959. UCHAR *tmp;
  960. UINT sz;
  961. UINT i;
  962. // Validate arguments
  963. if (buf == NULL || size == NULL)
  964. {
  965. return;
  966. }
  967. sz = TRAFFIC_BUF_SIZE;
  968. tmp = Malloc(sz);
  969. for (i = 0;i < sz;i++)
  970. {
  971. tmp[i] = rand() % 256;
  972. if (tmp[i] == '!')
  973. {
  974. tmp[i] = '_';
  975. }
  976. }
  977. *buf = tmp;
  978. *size = sz;
  979. }
  980. // Communication throughput measurement server worker thread
  981. void TtsWorkerThread(THREAD *thread, void *param)
  982. {
  983. TTS *tts;
  984. UINT buf_size;
  985. UCHAR *send_buf_data, *recv_buf_data;
  986. bool all_sockets_blocked = false;
  987. UINT64 tmp64;
  988. LIST *o;
  989. UINT i;
  990. wchar_t tmp[MAX_SIZE];
  991. bool dont_block_next_time = false;
  992. char *ver_str = TRAFFIC_VER_STR;
  993. // Validate arguments
  994. if (thread == NULL || param == NULL)
  995. {
  996. return;
  997. }
  998. // Allocate the data area
  999. TtGenerateRandomData(&send_buf_data, &buf_size);
  1000. TtGenerateRandomData(&recv_buf_data, &buf_size);
  1001. tts = (TTS *)param;
  1002. // Preparation of socket events
  1003. tts->SockEvent = NewSockEvent();
  1004. AddRef(tts->SockEvent->ref);
  1005. // Preparing the Server socket list
  1006. tts->TtsSockList = NewList(NULL);
  1007. // Notify completion of preparation to parent thread
  1008. NoticeThreadInit(thread);
  1009. o = NewList(NULL);
  1010. while (tts->Halt == false)
  1011. {
  1012. UINT64 now = Tick64();
  1013. // Wait for all sockets
  1014. if (dont_block_next_time == false)
  1015. {
  1016. WaitSockEvent(tts->SockEvent, 50);
  1017. }
  1018. dont_block_next_time = false;
  1019. // Process for sockets that are currently registered
  1020. LockList(tts->TtsSockList);
  1021. {
  1022. UINT i;
  1023. all_sockets_blocked = false;
  1024. // Continue to send and receive data
  1025. // until all sockets become block state
  1026. while (all_sockets_blocked == false)
  1027. {
  1028. all_sockets_blocked = true;
  1029. for (i = 0;i < LIST_NUM(tts->TtsSockList);i++)
  1030. {
  1031. UINT ret = SOCK_LATER;
  1032. UCHAR *send_data = NULL, *recv_data = NULL;
  1033. UINT send_size = 0, recv_size = 0;
  1034. TTS_SOCK *ts = LIST_DATA(tts->TtsSockList, i);
  1035. bool blocked_for_this_socket = false;
  1036. if (ts->SockJoined == false)
  1037. {
  1038. JoinSockToSockEvent(ts->Sock, tts->SockEvent);
  1039. ts->SockJoined = true;
  1040. }
  1041. switch (ts->State)
  1042. {
  1043. case 0:
  1044. // Return the version string
  1045. ret = Send(ts->Sock, ver_str, TRAFFIC_VER_STR_SIZE, false);
  1046. if (ret != 0 && ret != SOCK_LATER)
  1047. {
  1048. ts->State = 5;
  1049. }
  1050. break;
  1051. case 5:
  1052. // Receive the direction from the client
  1053. ret = Recv(ts->Sock, recv_buf_data, buf_size, false);
  1054. if (ret != 0 && ret != SOCK_LATER)
  1055. {
  1056. UCHAR c;
  1057. // Direction of the data is in the first byte that is received
  1058. c = recv_buf_data[0];
  1059. if (c == 0)
  1060. {
  1061. // In the case of 0, Client -> Server
  1062. ts->State = 1;
  1063. }
  1064. else
  1065. {
  1066. // Otherwise Server -> Client
  1067. ts->State = 2;
  1068. }
  1069. if (ret >= (sizeof(UINT64) + sizeof(UINT64) + 1))
  1070. {
  1071. // Session ID
  1072. ts->SessionId = READ_UINT64(recv_buf_data + 1);
  1073. // Span
  1074. ts->Span = READ_UINT64(recv_buf_data + sizeof(UINT64) + 1);
  1075. }
  1076. }
  1077. break;
  1078. case 1:
  1079. // Client -> Server
  1080. ret = Recv(ts->Sock, recv_buf_data, buf_size, false);
  1081. if (ret != 0 && ret != SOCK_LATER)
  1082. {
  1083. // Checking the first byte of received
  1084. UCHAR c = recv_buf_data[0];
  1085. if (ts->FirstRecvTick == 0)
  1086. {
  1087. // Record the time at which the data has been received for the first
  1088. ts->FirstRecvTick = now;
  1089. }
  1090. else
  1091. {
  1092. // Check whether the span didn't finish yet
  1093. if (ts->FirstRecvTick <= now)
  1094. {
  1095. if (ts->Span != 0)
  1096. {
  1097. UINT64 giveup_tick = ts->FirstRecvTick + ts->Span;
  1098. if (now > giveup_tick)
  1099. {
  1100. // Span has expired
  1101. c = '!';
  1102. }
  1103. }
  1104. }
  1105. }
  1106. if (c == '!')
  1107. {
  1108. // Notice the size information from the server to the client
  1109. ts->State = 3;
  1110. Debug("!");
  1111. }
  1112. }
  1113. break;
  1114. case 2:
  1115. // Server -> Client
  1116. if (ts->NoMoreSendData == false)
  1117. {
  1118. ret = Send(ts->Sock, send_buf_data, buf_size, false);
  1119. }
  1120. else
  1121. {
  1122. ret = Recv(ts->Sock, recv_buf_data, buf_size, false);
  1123. }
  1124. break;
  1125. case 3:
  1126. // Notice the size information from the server to the client
  1127. tmp64 = Endian64(ts->NumBytes);
  1128. Recv(ts->Sock, recv_buf_data, buf_size, false);
  1129. if (ts->LastWaitTick == 0 || ts->LastWaitTick <= Tick64())
  1130. {
  1131. ret = Send(ts->Sock, &tmp64, sizeof(tmp64), false);
  1132. if (ret != SOCK_LATER)
  1133. {
  1134. UINT j;
  1135. ts->LastWaitTick = Tick64() + 100;
  1136. if (ts->SessionId != 0)
  1137. {
  1138. // Not to send more data to the socket of the
  1139. // transmission direction in the same session ID
  1140. for (j = 0;j < LIST_NUM(tts->TtsSockList);j++)
  1141. {
  1142. TTS_SOCK *ts2 = LIST_DATA(tts->TtsSockList, j);
  1143. if (ts2->SessionId == ts->SessionId &&
  1144. ts2 != ts)
  1145. {
  1146. ts2->NoMoreSendData = true;
  1147. }
  1148. }
  1149. }
  1150. }
  1151. }
  1152. break;
  1153. }
  1154. if (ret == 0)
  1155. {
  1156. // Mark as deleting the socket because it is disconnected
  1157. Insert(o, ts);
  1158. }
  1159. else if (ret == SOCK_LATER)
  1160. {
  1161. // Delay has occurred
  1162. blocked_for_this_socket = true;
  1163. dont_block_next_time = false;
  1164. }
  1165. else
  1166. {
  1167. if (ts->State == 1)
  1168. {
  1169. ts->NumBytes += (UINT64)ret;
  1170. }
  1171. }
  1172. if (blocked_for_this_socket == false)
  1173. {
  1174. all_sockets_blocked = false;
  1175. }
  1176. }
  1177. if (LIST_NUM(o) != 0)
  1178. {
  1179. UINT i;
  1180. // One or more sockets is disconnected
  1181. for (i = 0;i < LIST_NUM(o);i++)
  1182. {
  1183. TTS_SOCK *ts = LIST_DATA(o, i);
  1184. UniFormat(tmp, sizeof(tmp), _UU("TTS_DISCONNECTED"), ts->Id, ts->Sock->RemoteHostname);
  1185. TtPrint(tts->Param, tts->Print, tmp);
  1186. Disconnect(ts->Sock);
  1187. ReleaseSock(ts->Sock);
  1188. Delete(tts->TtsSockList, ts);
  1189. Free(ts);
  1190. }
  1191. DeleteAll(o);
  1192. }
  1193. if (tts->NewSocketArrived || tts->Halt)
  1194. {
  1195. tts->NewSocketArrived = false;
  1196. all_sockets_blocked = true;
  1197. dont_block_next_time = true;
  1198. }
  1199. }
  1200. }
  1201. UnlockList(tts->TtsSockList);
  1202. }
  1203. LockList(tts->TtsSockList);
  1204. {
  1205. // Release the sockets of all remaining
  1206. for (i = 0;i < LIST_NUM(tts->TtsSockList);i++)
  1207. {
  1208. TTS_SOCK *ts = LIST_DATA(tts->TtsSockList, i);
  1209. UniFormat(tmp, sizeof(tmp), _UU("TTS_DISCONNECT"), ts->Id, ts->Sock->RemoteHostname);
  1210. TtPrint(tts->Param, tts->Print, tmp);
  1211. Disconnect(ts->Sock);
  1212. ReleaseSock(ts->Sock);
  1213. Free(ts);
  1214. }
  1215. }
  1216. UnlockList(tts->TtsSockList);
  1217. // Cleanup
  1218. ReleaseList(o);
  1219. ReleaseList(tts->TtsSockList);
  1220. ReleaseSockEvent(tts->SockEvent);
  1221. Free(send_buf_data);
  1222. Free(recv_buf_data);
  1223. }
  1224. // Accept thread for IPv6
  1225. void TtsIPv6AcceptThread(THREAD *thread, void *param)
  1226. {
  1227. TTS *tts = (TTS *)param;
  1228. // Validate arguments
  1229. if (tts == NULL || param == NULL)
  1230. {
  1231. return;
  1232. }
  1233. TtsAcceptProc(tts, tts->ListenSocketV6);
  1234. }
  1235. // Accept procedure
  1236. void TtsAcceptProc(TTS *tts, SOCK *listen_socket)
  1237. {
  1238. wchar_t tmp[MAX_SIZE];
  1239. // Validate arguments
  1240. if (tts == NULL || listen_socket == NULL)
  1241. {
  1242. return;
  1243. }
  1244. while (tts->Halt == false)
  1245. {
  1246. SOCK *s;
  1247. // Accept
  1248. s = Accept(listen_socket);
  1249. if (s == NULL)
  1250. {
  1251. if (tts->Halt == false)
  1252. {
  1253. SleepThread(10);
  1254. }
  1255. continue;
  1256. }
  1257. else
  1258. {
  1259. // Connected from the client
  1260. AcceptInit(s);
  1261. tts->NewSocketArrived = true;
  1262. LockList(tts->TtsSockList);
  1263. {
  1264. TTS_SOCK *ts = ZeroMalloc(sizeof(TTS_SOCK));
  1265. ts->Id = (++tts->IdSeed);
  1266. ts->Sock = s;
  1267. UniFormat(tmp, sizeof(tmp), _UU("TTS_ACCEPTED"), ts->Id,
  1268. s->RemoteHostname, s->RemotePort);
  1269. TtPrint(tts->Param, tts->Print, tmp);
  1270. Insert(tts->TtsSockList, ts);
  1271. tts->NewSocketArrived = true;
  1272. }
  1273. UnlockList(tts->TtsSockList);
  1274. SetSockEvent(tts->SockEvent);
  1275. }
  1276. }
  1277. }
  1278. // Communication throughput measurement server wait thread
  1279. void TtsListenThread(THREAD *thread, void *param)
  1280. {
  1281. TTS *tts;
  1282. wchar_t tmp[MAX_SIZE];
  1283. // Validate arguments
  1284. if (thread == NULL || param == NULL)
  1285. {
  1286. return;
  1287. }
  1288. tts = (TTS *)param;
  1289. tts->ListenSocket = NULL;
  1290. tts->ListenSocket = ListenEx(tts->Port, false);
  1291. tts->ListenSocketV6 = ListenEx6(tts->Port, false);
  1292. if (tts->ListenSocket == NULL && tts->ListenSocketV6 == NULL)
  1293. {
  1294. // Failed to Listen
  1295. UniFormat(tmp, sizeof(tmp), _UU("TT_LISTEN_FAILED"), tts->Port);
  1296. TtPrint(tts->Param, tts->Print, tmp);
  1297. // Notify completion of preparation to parent thread
  1298. NoticeThreadInit(thread);
  1299. tts->ErrorCode = ERR_INTERNAL_ERROR;
  1300. }
  1301. else
  1302. {
  1303. UniFormat(tmp, sizeof(tmp), _UU("TTS_LISTEN_STARTED"), tts->Port);
  1304. TtPrint(tts->Param, tts->Print, tmp);
  1305. if (tts->ListenSocketV6 != NULL)
  1306. {
  1307. UniFormat(tmp, sizeof(tmp), _UU("TTS_LISTEN_STARTED_V6"), tts->Port);
  1308. TtPrint(tts->Param, tts->Print, tmp);
  1309. }
  1310. else
  1311. {
  1312. UniFormat(tmp, sizeof(tmp), _UU("TTS_LISTEN_FAILED_V6"), tts->Port);
  1313. TtPrint(tts->Param, tts->Print, tmp);
  1314. }
  1315. if (tts->ListenSocket != NULL)
  1316. {
  1317. AddRef(tts->ListenSocket->ref);
  1318. }
  1319. if (tts->ListenSocketV6 != NULL)
  1320. {
  1321. AddRef(tts->ListenSocketV6->ref);
  1322. }
  1323. // Start the worker thread
  1324. tts->WorkThread = NewThread(TtsWorkerThread, tts);
  1325. WaitThreadInit(tts->WorkThread);
  1326. // Notify completion of preparation to parent thread
  1327. NoticeThreadInit(thread);
  1328. // Prepare for IPv6 Accept thread
  1329. tts->IPv6AcceptThread = NULL;
  1330. if (tts->ListenSocketV6 != NULL)
  1331. {
  1332. tts->IPv6AcceptThread = NewThread(TtsIPv6AcceptThread, tts);
  1333. }
  1334. TtsAcceptProc(tts, tts->ListenSocket);
  1335. if (tts->IPv6AcceptThread != NULL)
  1336. {
  1337. WaitThread(tts->IPv6AcceptThread, INFINITE);
  1338. ReleaseThread(tts->IPv6AcceptThread);
  1339. }
  1340. TtPrint(tts->Param, tts->Print, _UU("TTS_LISTEN_STOP"));
  1341. ReleaseSock(tts->ListenSocket);
  1342. ReleaseSock(tts->ListenSocketV6);
  1343. SetSockEvent(tts->SockEvent);
  1344. // Wait for stopping the worker thread
  1345. WaitThread(tts->WorkThread, INFINITE);
  1346. ReleaseThread(tts->WorkThread);
  1347. ReleaseSockEvent(tts->SockEvent);
  1348. }
  1349. }
  1350. // String of the direction in which data flows
  1351. wchar_t *GetTtcTypeStr(UINT type)
  1352. {
  1353. switch (type)
  1354. {
  1355. case TRAFFIC_TYPE_DOWNLOAD:
  1356. return _UU("TTC_TYPE_DOWNLOAD");
  1357. case TRAFFIC_TYPE_UPLOAD:
  1358. return _UU("TTC_TYPE_UPLOAD");
  1359. default:
  1360. return _UU("TTC_TYPE_FULL");
  1361. }
  1362. }
  1363. // Show a Summary
  1364. void TtcPrintSummary(TTC *ttc)
  1365. {
  1366. wchar_t tmp[MAX_SIZE];
  1367. wchar_t tmp2[MAX_SIZE];
  1368. wchar_t *tag = L"%-35s %s";
  1369. // Validate arguments
  1370. if (ttc == NULL)
  1371. {
  1372. return;
  1373. }
  1374. TtPrint(ttc->Param, ttc->Print, L"");
  1375. TtPrint(ttc->Param, ttc->Print, _UU("TTC_SUMMARY_BAR"));
  1376. TtPrint(ttc->Param, ttc->Print, _UU("TTC_SUMMARY_TITLE"));
  1377. TtPrint(ttc->Param, ttc->Print, L"");
  1378. // Destination host name
  1379. StrToUni(tmp2, sizeof(tmp2), ttc->Host);
  1380. UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_HOST"), tmp2);
  1381. TtPrint(ttc->Param, ttc->Print, tmp);
  1382. // Destination TCP port number
  1383. UniToStru(tmp2, ttc->Port);
  1384. UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_PORT"), tmp2);
  1385. TtPrint(ttc->Param, ttc->Print, tmp);
  1386. // Number of TCP connections to establish
  1387. UniToStru(tmp2, ttc->NumTcp);
  1388. UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_NUMTCP"), tmp2);
  1389. TtPrint(ttc->Param, ttc->Print, tmp);
  1390. // Data transmission direction
  1391. UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_TYPE"), GetTtcTypeStr(ttc->Type));
  1392. TtPrint(ttc->Param, ttc->Print, tmp);
  1393. // Data transmission span
  1394. UniFormat(tmp2, sizeof(tmp2), _UU("TTC_SPAN_STR"), (double)(ttc->Span) / 1000.0);
  1395. UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_SPAN"), tmp2);
  1396. TtPrint(ttc->Param, ttc->Print, tmp);
  1397. // Correct the data for Ethernet frame
  1398. UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_ETHER"), ttc->Raw ? _UU("SEC_NO") : _UU("SEC_YES"));
  1399. TtPrint(ttc->Param, ttc->Print, tmp);
  1400. // Measure the total amount of input and output throughput of relay equipment
  1401. UniFormat(tmp, sizeof(tmp), tag, _UU("TTC_SUMMARY_DOUBLE"), ttc->Double ? _UU("SEC_YES") : _UU("SEC_NO"));
  1402. TtPrint(ttc->Param, ttc->Print, tmp);
  1403. TtPrint(ttc->Param, ttc->Print, _UU("TTC_SUMMARY_BAR"));
  1404. TtPrint(ttc->Param, ttc->Print, L"");
  1405. }
  1406. // Stop the communication throughput measurement client
  1407. void StopTtc(TTC *ttc)
  1408. {
  1409. // Validate arguments
  1410. if (ttc == NULL)
  1411. {
  1412. return;
  1413. }
  1414. TtPrint(ttc->Param, ttc->Print, _UU("TTC_STOPPING"));
  1415. ttc->Halt = true;
  1416. SetSockEvent(ttc->SockEvent);
  1417. }
  1418. // Generate a result
  1419. void TtcGenerateResult(TTC *ttc)
  1420. {
  1421. TT_RESULT *res;
  1422. UINT i;
  1423. // Validate arguments
  1424. if (ttc == NULL)
  1425. {
  1426. return;
  1427. }
  1428. res = &ttc->Result;
  1429. Zero(res, sizeof(TT_RESULT));
  1430. res->Raw = ttc->Raw;
  1431. res->Double = ttc->Double;
  1432. res->Span = ttc->RealSpan;
  1433. for (i = 0;i < LIST_NUM(ttc->ItcSockList);i++)
  1434. {
  1435. TTC_SOCK *ts = LIST_DATA(ttc->ItcSockList, i);
  1436. if (ts->Download == false)
  1437. {
  1438. // Upload
  1439. res->NumBytesUpload += ts->NumBytes;
  1440. }
  1441. else
  1442. {
  1443. // Download
  1444. res->NumBytesDownload += ts->NumBytes;
  1445. }
  1446. }
  1447. if (res->Raw == false)
  1448. {
  1449. // Correct to match the Ethernet
  1450. res->NumBytesDownload = (UINT64)((double)res->NumBytesDownload * 1514.0 / 1460.0);
  1451. res->NumBytesUpload = (UINT64)((double)res->NumBytesUpload * 1514.0 / 1460.0);
  1452. }
  1453. res->NumBytesTotal = res->NumBytesDownload + res->NumBytesUpload;
  1454. // Measure the throughput
  1455. if (res->Span != 0)
  1456. {
  1457. res->BpsUpload = (UINT64)((double)res->NumBytesUpload * 8.0 / ((double)res->Span / 1000.0));
  1458. res->BpsDownload = (UINT64)((double)res->NumBytesDownload * 8.0 / ((double)res->Span / 1000.0));
  1459. }
  1460. if (res->Double)
  1461. {
  1462. res->BpsUpload *= 2ULL;
  1463. res->BpsDownload *= 2ULL;
  1464. }
  1465. res->BpsTotal = res->BpsUpload + res->BpsDownload;
  1466. }
  1467. // Client thread
  1468. void TtcThread(THREAD *thread, void *param)
  1469. {
  1470. TTC *ttc;
  1471. UINT i;
  1472. wchar_t tmp[MAX_SIZE];
  1473. bool ok = false;
  1474. UINT buf_size;
  1475. UCHAR *send_buf_data, *recv_buf_data;
  1476. // Validate arguments
  1477. if (thread == NULL || param == NULL)
  1478. {
  1479. return;
  1480. }
  1481. // Allocate the data area
  1482. TtGenerateRandomData(&send_buf_data, &buf_size);
  1483. TtGenerateRandomData(&recv_buf_data, &buf_size);
  1484. ttc = (TTC *)param;
  1485. ttc->SockEvent = NewSockEvent();
  1486. AddRef(ttc->SockEvent->ref);
  1487. // Ready
  1488. NoticeThreadInit(thread);
  1489. TtcPrintSummary(ttc);
  1490. UniFormat(tmp, sizeof(tmp), _UU("TTC_CONNECT_START"),
  1491. ttc->Host, ttc->Port, ttc->NumTcp);
  1492. TtPrint(ttc->Param, ttc->Print, tmp);
  1493. // Establish all connections to the client
  1494. ttc->ItcSockList = NewList(NULL);
  1495. ok = true;
  1496. for (i = 0;i < ttc->NumTcp;i++)
  1497. {
  1498. SOCK *s;
  1499. TTC_SOCK *ts = ZeroMalloc(sizeof(TTC_SOCK));
  1500. ts->Id = i + 1;
  1501. if (ttc->Type == TRAFFIC_TYPE_DOWNLOAD)
  1502. {
  1503. ts->Download = true;
  1504. }
  1505. else if (ttc->Type == TRAFFIC_TYPE_UPLOAD)
  1506. {
  1507. ts->Download = false;
  1508. }
  1509. else
  1510. {
  1511. ts->Download = ((i % 2) == 0) ? true : false;
  1512. }
  1513. s = ConnectEx2(ttc->Host, ttc->Port, 0, ttc->Cancel);
  1514. if (s == NULL)
  1515. {
  1516. UniFormat(tmp, sizeof(tmp), _UU("TTC_CONNECT_FAILED"), i + 1);
  1517. TtPrint(ttc->Param, ttc->Print, tmp);
  1518. ok = false;
  1519. Free(ts);
  1520. break;
  1521. }
  1522. else
  1523. {
  1524. char buffer[TRAFFIC_VER_STR_SIZE];
  1525. SetTimeout(s, 5000);
  1526. Zero(buffer, sizeof(buffer));
  1527. if (Recv(s, buffer, sizeof(buffer), false) != sizeof(buffer) || Cmp(buffer, TRAFFIC_VER_STR, TRAFFIC_VER_STR_SIZE) != 0)
  1528. {
  1529. TtPrint(ttc->Param, ttc->Print, _UU("TTC_CONNECT_NOT_SERVER"));
  1530. ok = false;
  1531. ReleaseSock(s);
  1532. Free(ts);
  1533. break;
  1534. }
  1535. UniFormat(tmp, sizeof(tmp), _UU("TTC_CONNECT_OK"), i + 1);
  1536. TtPrint(ttc->Param, ttc->Print, tmp);
  1537. UniFormat(tmp, sizeof(tmp), _UU("TTC_CONNECT_OK_2"), GetTtcTypeStr(ts->Download ? TRAFFIC_TYPE_DOWNLOAD : TRAFFIC_TYPE_UPLOAD));
  1538. TtPrint(ttc->Param, ttc->Print, tmp);
  1539. ts->Sock = s;
  1540. SetTimeout(s, TIMEOUT_INFINITE);
  1541. JoinSockToSockEvent(s, ttc->SockEvent);
  1542. }
  1543. Insert(ttc->ItcSockList, ts);
  1544. }
  1545. Set(ttc->InitedEvent);
  1546. if (ttc->StartEvent != NULL)
  1547. {
  1548. Wait(ttc->StartEvent, INFINITE);
  1549. SleepThread(500);
  1550. }
  1551. if (ok)
  1552. {
  1553. bool all_sockets_blocked;
  1554. bool dont_block_next_time = false;
  1555. bool halt_flag = false;
  1556. UINT64 start_tick, end_tick;
  1557. UINT64 halt_timeout = 0;
  1558. wchar_t tmp1[MAX_SIZE], tmp2[MAX_SIZE];
  1559. UINT check_clock_seed = 0;
  1560. bool halting = false;
  1561. UINT64 tmp64;
  1562. UINT64 session_id = Rand64();
  1563. // Record the current time
  1564. start_tick = Tick64();
  1565. end_tick = start_tick + ttc->Span;
  1566. // Show start message
  1567. GetDateTimeStrEx64(tmp1, sizeof(tmp1), SystemToLocal64(TickToTime(start_tick)), NULL);
  1568. GetDateTimeStrEx64(tmp2, sizeof(tmp2), SystemToLocal64(TickToTime(end_tick)), NULL);
  1569. UniFormat(tmp, sizeof(tmp), _UU("TTC_COMM_START"), tmp1, tmp2);
  1570. TtPrint(ttc->Param, ttc->Print, tmp);
  1571. // Main loop
  1572. while (true)
  1573. {
  1574. UINT i;
  1575. if (dont_block_next_time == false)
  1576. {
  1577. WaitSockEvent(ttc->SockEvent, 50);
  1578. }
  1579. dont_block_next_time = false;
  1580. if (ttc->AbnormalTerminated)
  1581. {
  1582. // Abnormal termination occured
  1583. break;
  1584. }
  1585. if (ttc->Halt || end_tick <= Tick64() || (ttc->Cancel != NULL && (*ttc->Cancel)))
  1586. {
  1587. // End measurement
  1588. if (halting == false)
  1589. {
  1590. if (ttc->Halt || (ttc->Cancel != NULL && (*ttc->Cancel)))
  1591. {
  1592. // User cancel
  1593. TtPrint(ttc->Param, ttc->Print, _UU("TTC_COMM_USER_CANCEL"));
  1594. }
  1595. else
  1596. {
  1597. // Time elapsed
  1598. UniFormat(tmp, sizeof(tmp), _UU("TTC_COMM_END"),
  1599. (double)ttc->Span / 1000.0);
  1600. TtPrint(ttc->Param, ttc->Print, tmp);
  1601. }
  1602. ttc->RealSpan = Tick64() - start_tick;
  1603. halting = true;
  1604. // Wait for reporting data from the server
  1605. halt_timeout = Tick64() + 60000ULL;
  1606. }
  1607. }
  1608. if (halt_timeout != 0)
  1609. {
  1610. bool ok = true;
  1611. // Wait that all TCP connections to finish processing
  1612. for (i = 0;i < LIST_NUM(ttc->ItcSockList);i++)
  1613. {
  1614. TTC_SOCK *ts = LIST_DATA(ttc->ItcSockList, i);
  1615. if (ts->Download == false)
  1616. {
  1617. if (ts->ServerUploadReportReceived == false)
  1618. {
  1619. ok = false;
  1620. }
  1621. }
  1622. }
  1623. if (ok)
  1624. {
  1625. // Measurement completed
  1626. // Show the result
  1627. TtcGenerateResult(ttc);
  1628. break;
  1629. }
  1630. else
  1631. {
  1632. if (halt_timeout <= Tick64())
  1633. {
  1634. // An error occured
  1635. ttc->AbnormalTerminated = true;
  1636. ttc->ErrorCode = ERR_PROTOCOL_ERROR;
  1637. break;
  1638. }
  1639. }
  1640. }
  1641. all_sockets_blocked = false;
  1642. // Continue to send and receive data
  1643. // until all sockets become block state
  1644. while (all_sockets_blocked == false)
  1645. {
  1646. all_sockets_blocked = true;
  1647. for (i = 0;i < LIST_NUM(ttc->ItcSockList);i++)
  1648. {
  1649. UINT ret = SOCK_LATER;
  1650. TTC_SOCK *ts = LIST_DATA(ttc->ItcSockList, i);
  1651. bool blocked_for_this_socket = false;
  1652. UCHAR c = 0;
  1653. UCHAR c_and_session_id[1 + sizeof(UINT64) + sizeof(UINT64)];
  1654. if (halt_timeout != 0)
  1655. {
  1656. if (ts->State != 3 && ts->State != 4)
  1657. {
  1658. if (ts->Download == false)
  1659. {
  1660. if (ts->State != 0)
  1661. {
  1662. ts->State = 3;
  1663. }
  1664. else
  1665. {
  1666. ts->ServerUploadReportReceived = true;
  1667. ts->State = 4;
  1668. }
  1669. }
  1670. else
  1671. {
  1672. ts->State = 4;
  1673. }
  1674. }
  1675. }
  1676. switch (ts->State)
  1677. {
  1678. case 0:
  1679. // Initial state: Specify the direction of
  1680. // the data flow between client-server
  1681. if (ts->Download)
  1682. {
  1683. c = 1;
  1684. }
  1685. else
  1686. {
  1687. c = 0;
  1688. }
  1689. c_and_session_id[0] = c;
  1690. WRITE_UINT64(c_and_session_id + 1, session_id);
  1691. WRITE_UINT64(c_and_session_id + sizeof(UINT64) + 1, ttc->Span);
  1692. ret = Send(ts->Sock, c_and_session_id, 1 + sizeof(UINT64) + sizeof(UINT64), false);
  1693. if (ret != 0 && ret != SOCK_LATER)
  1694. {
  1695. if (ts->Download)
  1696. {
  1697. ts->State = 1;
  1698. }
  1699. else
  1700. {
  1701. ts->State = 2;
  1702. }
  1703. }
  1704. break;
  1705. case 1:
  1706. // Server -> Client (download)
  1707. ret = Recv(ts->Sock, recv_buf_data, buf_size, false);
  1708. break;
  1709. case 2:
  1710. // Client -> Server (upload)
  1711. ret = Send(ts->Sock, send_buf_data, buf_size, false);
  1712. break;
  1713. case 3:
  1714. // Transmission completion client -> server (upload)
  1715. // Request the data size
  1716. if (ts->NextSendRequestReportTick == 0 ||
  1717. (Tick64() >= ts->NextSendRequestReportTick))
  1718. {
  1719. UCHAR suprise[MAX_SIZE];
  1720. UINT i;
  1721. ts->NextSendRequestReportTick = Tick64() + 200ULL;
  1722. for (i = 0;i < sizeof(suprise);i++)
  1723. {
  1724. suprise[i] = '!';
  1725. }
  1726. ret = Send(ts->Sock, suprise, sizeof(suprise), false);
  1727. }
  1728. ret = Recv(ts->Sock, &tmp64, sizeof(tmp64), false);
  1729. if (ret != 0 && ret != SOCK_LATER && ret == sizeof(tmp64))
  1730. {
  1731. ts->NumBytes = Endian64(tmp64);
  1732. ts->ServerUploadReportReceived = true;
  1733. ts->State = 4;
  1734. }
  1735. break;
  1736. case 4:
  1737. // Do Nothing
  1738. if (Recv(ts->Sock, recv_buf_data, buf_size, false) == SOCK_LATER)
  1739. {
  1740. ret = SOCK_LATER;
  1741. }
  1742. break;
  1743. }
  1744. if (ret == 0)
  1745. {
  1746. // The socket is disconnected
  1747. ttc->AbnormalTerminated = true;
  1748. ttc->ErrorCode = ERR_PROTOCOL_ERROR;
  1749. blocked_for_this_socket = true;
  1750. dont_block_next_time = false;
  1751. if (ts->HideErrMsg == false)
  1752. {
  1753. UniFormat(tmp, sizeof(tmp), _UU("TTC_COMM_DISCONNECTED"), ts->Id);
  1754. TtPrint(ttc->Param, ttc->Print, tmp);
  1755. ts->HideErrMsg = true;
  1756. }
  1757. }
  1758. else if (ret == SOCK_LATER)
  1759. {
  1760. // Delay has occurred
  1761. blocked_for_this_socket = true;
  1762. dont_block_next_time = false;
  1763. }
  1764. else
  1765. {
  1766. if (ts->Download)
  1767. {
  1768. ts->NumBytes += (UINT64)ret;
  1769. }
  1770. }
  1771. if (blocked_for_this_socket == false)
  1772. {
  1773. all_sockets_blocked = false;
  1774. }
  1775. }
  1776. if (ttc->Halt || (ttc->Cancel != NULL && (*ttc->Cancel)))
  1777. {
  1778. all_sockets_blocked = true;
  1779. dont_block_next_time = true;
  1780. }
  1781. if (end_tick <= Tick64())
  1782. {
  1783. all_sockets_blocked = true;
  1784. dont_block_next_time = true;
  1785. }
  1786. }
  1787. }
  1788. }
  1789. else
  1790. {
  1791. // Abort
  1792. TtPrint(ttc->Param, ttc->Print, _UU("TTC_ERROR_ABORTED"));
  1793. ttc->ErrorCode = ERR_CONNECT_FAILED;
  1794. }
  1795. // Cleanup
  1796. for (i = 0;i < LIST_NUM(ttc->ItcSockList);i++)
  1797. {
  1798. TTC_SOCK *ts = LIST_DATA(ttc->ItcSockList, i);
  1799. Disconnect(ts->Sock);
  1800. ReleaseSock(ts->Sock);
  1801. Free(ts);
  1802. }
  1803. ReleaseSockEvent(ttc->SockEvent);
  1804. ReleaseList(ttc->ItcSockList);
  1805. Free(send_buf_data);
  1806. Free(recv_buf_data);
  1807. }
  1808. // Start the communication throughput measurement client
  1809. TTC *NewTtc(char *host, UINT port, UINT numtcp, UINT type, UINT64 span, bool dbl, bool raw, TT_PRINT_PROC *print_proc, void *param)
  1810. {
  1811. return NewTtcEx(host, port, numtcp, type, span, dbl, raw, print_proc, param, NULL, NULL);
  1812. }
  1813. TTC *NewTtcEx(char *host, UINT port, UINT numtcp, UINT type, UINT64 span, bool dbl, bool raw, TT_PRINT_PROC *print_proc, void *param, EVENT *start_event, bool *cancel)
  1814. {
  1815. TTC *ttc;
  1816. ttc = ZeroMalloc(sizeof(TTC));
  1817. ttc->InitedEvent = NewEvent();
  1818. ttc->Port = port;
  1819. StrCpy(ttc->Host, sizeof(ttc->Host), host);
  1820. ttc->NumTcp = numtcp;
  1821. ttc->Type = type;
  1822. ttc->Span = span;
  1823. ttc->Double = dbl;
  1824. ttc->Raw = raw;
  1825. ttc->StartEvent = start_event;
  1826. ttc->Cancel = cancel;
  1827. if (ttc->Type == TRAFFIC_TYPE_FULL && ttc->NumTcp < 2)
  1828. {
  1829. ttc->NumTcp = 2;
  1830. }
  1831. ttc->Print = print_proc;
  1832. ttc->Param = param;
  1833. ttc->ErrorCode = ERR_NO_ERROR;
  1834. TtPrint(ttc->Param, ttc->Print, _UU("TTC_INIT"));
  1835. ttc->Thread = NewThread(TtcThread, ttc);
  1836. WaitThreadInit(ttc->Thread);
  1837. return ttc;
  1838. }
  1839. // Wait for stopping the communication throughput measurement client
  1840. UINT FreeTtc(TTC *ttc, TT_RESULT *result)
  1841. {
  1842. UINT ret;
  1843. // Validate arguments
  1844. if (ttc == NULL)
  1845. {
  1846. return ERR_INVALID_PARAMETER;
  1847. }
  1848. WaitThread(ttc->Thread, INFINITE);
  1849. ReleaseThread(ttc->Thread);
  1850. TtPrint(ttc->Param, ttc->Print, _UU("TTC_FREE"));
  1851. ret = ttc->ErrorCode;
  1852. if (ret == ERR_NO_ERROR)
  1853. {
  1854. if (result != NULL)
  1855. {
  1856. Copy(result, &ttc->Result, sizeof(TT_RESULT));
  1857. }
  1858. }
  1859. ReleaseSockEvent(ttc->SockEvent);
  1860. ReleaseEvent(ttc->InitedEvent);
  1861. Free(ttc);
  1862. return ret;
  1863. }
  1864. // Start the communication throughput measurement server
  1865. TTS *NewTts(UINT port, void *param, TT_PRINT_PROC *print_proc)
  1866. {
  1867. TTS *tts;
  1868. THREAD *t;
  1869. tts = ZeroMalloc(sizeof(TTS));
  1870. tts->Port = port;
  1871. tts->Param = param;
  1872. tts->Print = print_proc;
  1873. TtPrint(param, print_proc, _UU("TTS_INIT"));
  1874. // Creating a thread
  1875. t = NewThread(TtsListenThread, tts);
  1876. WaitThreadInit(t);
  1877. tts->Thread = t;
  1878. return tts;
  1879. }
  1880. // Wait for stopping the communication throughput measurement server
  1881. UINT FreeTts(TTS *tts)
  1882. {
  1883. UINT ret;
  1884. // Validate arguments
  1885. if (tts == NULL)
  1886. {
  1887. return ERR_INVALID_PARAMETER;
  1888. }
  1889. TtPrint(tts->Param, tts->Print, _UU("TTS_STOP_INIT"));
  1890. tts->Halt = true;
  1891. Disconnect(tts->ListenSocket);
  1892. ReleaseSock(tts->ListenSocket);
  1893. Disconnect(tts->ListenSocketV6);
  1894. ReleaseSock(tts->ListenSocketV6);
  1895. // Wait for the termination of the thread
  1896. WaitThread(tts->Thread, INFINITE);
  1897. ReleaseThread(tts->Thread);
  1898. TtPrint(tts->Param, tts->Print, _UU("TTS_STOP_FINISHED"));
  1899. ret = tts->ErrorCode;
  1900. Free(tts);
  1901. return ret;
  1902. }
  1903. // Show the measurement tools prompt
  1904. void PtTrafficPrintProc(void *param, wchar_t *str)
  1905. {
  1906. CONSOLE *c;
  1907. // Validate arguments
  1908. if (param == NULL || str == NULL)
  1909. {
  1910. return;
  1911. }
  1912. c = (CONSOLE *)param;
  1913. if (c->ConsoleType == CONSOLE_LOCAL)
  1914. {
  1915. wchar_t tmp[MAX_SIZE];
  1916. // Display only if the local console
  1917. // (Can not be displayed because threads aren't synchronized otherwise?)
  1918. UniStrCpy(tmp, sizeof(tmp), str);
  1919. if (UniEndWith(str, L"\n") == false)
  1920. {
  1921. UniStrCat(tmp, sizeof(tmp), L"\n");
  1922. }
  1923. UniPrint(L"%s", tmp);
  1924. }
  1925. }
  1926. // Display the communication throughput results
  1927. void TtcPrintResult(CONSOLE *c, TT_RESULT *res)
  1928. {
  1929. CT *ct;
  1930. wchar_t tmp[MAX_SIZE];
  1931. wchar_t tmp1[MAX_SIZE];
  1932. wchar_t tmp2[MAX_SIZE];
  1933. char str[MAX_SIZE];
  1934. // Validate arguments
  1935. if (c == NULL || res == NULL)
  1936. {
  1937. return;
  1938. }
  1939. c->Write(c, _UU("TTC_RES_TITLE"));
  1940. ct = CtNew();
  1941. CtInsertColumn(ct, _UU("TTC_RES_COLUMN_1"), false);
  1942. CtInsertColumn(ct, _UU("TTC_RES_COLUMN_2"), true);
  1943. CtInsertColumn(ct, _UU("TTC_RES_COLUMN_3"), true);
  1944. // Time that was used to measure
  1945. GetSpanStrMilli(str, sizeof(str), res->Span);
  1946. StrToUni(tmp, sizeof(tmp), str);
  1947. CtInsert(ct, _UU("TTC_RES_SPAN"), tmp, L"");
  1948. // Correct the data for Ethernet frame
  1949. CtInsert(ct, _UU("TTC_RES_ETHER"), res->Raw ? _UU("SEC_NO") : _UU("SEC_YES"), L"");
  1950. // Amount of communication data of download direction
  1951. ToStr3(str, sizeof(str), res->NumBytesDownload);
  1952. UniFormat(tmp1, sizeof(tmp1), L"%S Bytes", str);
  1953. ToStrByte1000(str, sizeof(str), res->NumBytesDownload);
  1954. StrToUni(tmp2, sizeof(tmp2), str);
  1955. CtInsert(ct, _UU("TTC_RES_BYTES_DOWNLOAD"), tmp1, tmp2);
  1956. // Amount of communication data of upload direction
  1957. ToStr3(str, sizeof(str), res->NumBytesUpload);
  1958. UniFormat(tmp1, sizeof(tmp1), L"%S Bytes", str);
  1959. ToStrByte1000(str, sizeof(str), res->NumBytesUpload);
  1960. StrToUni(tmp2, sizeof(tmp2), str);
  1961. CtInsert(ct, _UU("TTC_RES_BYTES_UPLOAD"), tmp1, tmp2);
  1962. // Total amount of communication data
  1963. ToStr3(str, sizeof(str), res->NumBytesTotal);
  1964. UniFormat(tmp1, sizeof(tmp1), L"%S Bytes", str);
  1965. ToStrByte1000(str, sizeof(str), res->NumBytesTotal);
  1966. StrToUni(tmp2, sizeof(tmp2), str);
  1967. CtInsert(ct, _UU("TTC_RES_BYTES_TOTAL"), tmp1, tmp2);
  1968. // Calculate the total throughput of input and output of the relay equipment
  1969. CtInsert(ct, _UU("TTC_RES_DOUBLE"), (res->Double == false) ? _UU("SEC_NO") : _UU("SEC_YES"), L"");
  1970. // Average throughput of download direction
  1971. ToStr3(str, sizeof(str), res->BpsDownload);
  1972. UniFormat(tmp1, sizeof(tmp1), L"%S bps", str);
  1973. ToStrByte1000(str, sizeof(str), res->BpsDownload);
  1974. ReplaceStr(str, sizeof(str), str, "Bytes", "bps");
  1975. StrToUni(tmp2, sizeof(tmp2), str);
  1976. CtInsert(ct, _UU("TTC_RES_BPS_DOWNLOAD"), tmp1, tmp2);
  1977. // Average throughput of upload direction
  1978. ToStr3(str, sizeof(str), res->BpsUpload);
  1979. UniFormat(tmp1, sizeof(tmp1), L"%S bps", str);
  1980. ToStrByte1000(str, sizeof(str), res->BpsUpload);
  1981. ReplaceStr(str, sizeof(str), str, "Bytes", "bps");
  1982. StrToUni(tmp2, sizeof(tmp2), str);
  1983. CtInsert(ct, _UU("TTC_RES_BPS_UPLOAD"), tmp1, tmp2);
  1984. // Total average throughput
  1985. ToStr3(str, sizeof(str), res->BpsTotal);
  1986. UniFormat(tmp1, sizeof(tmp1), L"%S bps", str);
  1987. ToStrByte1000(str, sizeof(str), res->BpsTotal);
  1988. ReplaceStr(str, sizeof(str), str, "Bytes", "bps");
  1989. StrToUni(tmp2, sizeof(tmp2), str);
  1990. CtInsert(ct, _UU("TTC_RES_BPS_TOTAL"), tmp1, tmp2);
  1991. CtFree(ct, c);
  1992. }
  1993. // Execute the communication throughput measurement tool server
  1994. UINT PtTrafficServer(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  1995. {
  1996. LIST *o;
  1997. UINT ret = ERR_NO_ERROR;
  1998. UINT port;
  1999. bool nohup;
  2000. TTS *tts;
  2001. PARAM args[] =
  2002. {
  2003. {"[port]", NULL, NULL, NULL, NULL},
  2004. {"NOHUP", NULL, NULL, NULL, NULL},
  2005. };
  2006. // Get the parameter list
  2007. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  2008. if (o == NULL)
  2009. {
  2010. return ERR_INVALID_PARAMETER;
  2011. }
  2012. port = GetParamInt(o, "[port]");
  2013. if (port == 0)
  2014. {
  2015. port = TRAFFIC_DEFAULT_PORT;
  2016. }
  2017. nohup = GetParamYes(o, "nohup");
  2018. tts = NewTts(port, c, PtTrafficPrintProc);
  2019. if (nohup)
  2020. {
  2021. while (true)
  2022. {
  2023. SleepThread(10000);
  2024. }
  2025. }
  2026. c->Write(c, _UU("TTS_ENTER_TO_EXIT"));
  2027. Free(c->ReadLine(c, L"", true));
  2028. ret = tts->ErrorCode;
  2029. FreeTts(tts);
  2030. if (ret != ERR_NO_ERROR)
  2031. {
  2032. CmdPrintError(c, ret);
  2033. }
  2034. // Release of the parameter list
  2035. FreeParamValueList(o);
  2036. return ret;
  2037. }
  2038. // Execute the communication throughput measurement tool client
  2039. UINT PtTrafficClient(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2040. {
  2041. TTC *ttc;
  2042. LIST *o;
  2043. UINT ret = ERR_NO_ERROR;
  2044. char *host = NULL;
  2045. UINT port;
  2046. UINT num, type;
  2047. bool dbl = false, raw = false;
  2048. UINT64 span;
  2049. // Parameter list that can be specified
  2050. CMD_EVAL_MIN_MAX minmax =
  2051. {
  2052. "CMD_TrafficClient_EVAL_NUMTCP",
  2053. 0, TRAFFIC_NUMTCP_MAX,
  2054. };
  2055. PARAM args[] =
  2056. {
  2057. {"[host:port]", CmdPrompt, _UU("CMD_TrafficClient_PROMPT_HOST"), CmdEvalNotEmpty, NULL},
  2058. {"NUMTCP", NULL, NULL, CmdEvalMinMax, &minmax},
  2059. {"TYPE", NULL, NULL, NULL, NULL},
  2060. {"SPAN", NULL, NULL, NULL, NULL},
  2061. {"DOUBLE", NULL, NULL, NULL, NULL},
  2062. {"RAW", NULL, NULL, NULL, NULL},
  2063. };
  2064. // Get the parameter list
  2065. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  2066. if (o == NULL)
  2067. {
  2068. return ERR_INVALID_PARAMETER;
  2069. }
  2070. if (ParseHostPort(GetParamStr(o, "[host:port]"), &host, &port, TRAFFIC_DEFAULT_PORT) == false)
  2071. {
  2072. c->Write(c, _UU("CMD_TrafficClient_ERROR_HOSTPORT"));
  2073. ret = ERR_INVALID_PARAMETER;
  2074. }
  2075. else
  2076. {
  2077. char *s;
  2078. UINT i;
  2079. Trim(host);
  2080. num = GetParamInt(o, "NUMTCP");
  2081. if (num == 0)
  2082. {
  2083. num = TRAFFIC_NUMTCP_DEFAULT;
  2084. }
  2085. s = GetParamStr(o, "TYPE");
  2086. if (StartWith("download", s))
  2087. {
  2088. type = TRAFFIC_TYPE_DOWNLOAD;
  2089. }
  2090. else if (StartWith("upload", s))
  2091. {
  2092. type = TRAFFIC_TYPE_UPLOAD;
  2093. }
  2094. else
  2095. {
  2096. type = TRAFFIC_TYPE_FULL;
  2097. }
  2098. i = GetParamInt(o, "SPAN");
  2099. if (i == 0)
  2100. {
  2101. i = TRAFFIC_SPAN_DEFAULT;
  2102. }
  2103. span = (UINT64)i * 1000ULL;
  2104. dbl = GetParamYes(o, "DOUBLE");
  2105. raw = GetParamYes(o, "RAW");
  2106. if (type == TRAFFIC_TYPE_FULL)
  2107. {
  2108. if ((num % 2) != 0)
  2109. {
  2110. ret = ERR_INVALID_PARAMETER;
  2111. c->Write(c, _UU("CMD_TrafficClient_ERROR_NUMTCP"));
  2112. }
  2113. }
  2114. if (ret == ERR_NO_ERROR)
  2115. {
  2116. TT_RESULT result;
  2117. ttc = NewTtc(host, port, num, type, span, dbl, raw, PtTrafficPrintProc, c);
  2118. if (c->ConsoleType == CONSOLE_LOCAL)
  2119. {
  2120. if (c->Param != NULL && (((LOCAL_CONSOLE_PARAM *)c->Param)->InBuf == NULL))
  2121. {
  2122. // c->Write(c, _UU("TTC_ENTER_TO_EXIT"));
  2123. // GetLine(NULL, 0);
  2124. // StopTtc(ttc);
  2125. }
  2126. }
  2127. Zero(&result, sizeof(result));
  2128. ret = FreeTtc(ttc, &result);
  2129. if (ret == ERR_NO_ERROR)
  2130. {
  2131. TtcPrintResult(c, &result);
  2132. }
  2133. }
  2134. }
  2135. if (ret != ERR_NO_ERROR)
  2136. {
  2137. CmdPrintError(c, ret);
  2138. }
  2139. // Release of the parameter list
  2140. FreeParamValueList(o);
  2141. Free(host);
  2142. return ret;
  2143. }
  2144. // Certificate easy creation tool (1024 bit)
  2145. UINT PtMakeCert(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2146. {
  2147. LIST *o;
  2148. UINT ret = ERR_NO_ERROR;
  2149. X *x = NULL;
  2150. K *pub = NULL;
  2151. K *pri = NULL;
  2152. NAME *n;
  2153. X_SERIAL *x_serial = NULL;
  2154. BUF *buf;
  2155. UINT days;
  2156. X *root_x = NULL;
  2157. K *root_k = NULL;
  2158. // Parameter list that can be specified
  2159. CMD_EVAL_MIN_MAX minmax =
  2160. {
  2161. "CMD_MakeCert_EVAL_EXPIRES",
  2162. 0,
  2163. 10950,
  2164. };
  2165. PARAM args[] =
  2166. {
  2167. {"CN", CmdPrompt, _UU("CMD_MakeCert_PROMPT_CN"), NULL, NULL},
  2168. {"O", CmdPrompt, _UU("CMD_MakeCert_PROMPT_O"), NULL, NULL},
  2169. {"OU", CmdPrompt, _UU("CMD_MakeCert_PROMPT_OU"), NULL, NULL},
  2170. {"C", CmdPrompt, _UU("CMD_MakeCert_PROMPT_C"), NULL, NULL},
  2171. {"ST", CmdPrompt, _UU("CMD_MakeCert_PROMPT_ST"), NULL, NULL},
  2172. {"L", CmdPrompt, _UU("CMD_MakeCert_PROMPT_L"), NULL, NULL},
  2173. {"SERIAL", CmdPrompt, _UU("CMD_MakeCert_PROMPT_SERIAL"), NULL, NULL},
  2174. {"EXPIRES", CmdPrompt, _UU("CMD_MakeCert_PROMPT_EXPIRES"), CmdEvalMinMax, &minmax},
  2175. {"SIGNCERT", NULL, NULL, CmdEvalIsFile, NULL},
  2176. {"SIGNKEY", NULL, NULL, CmdEvalIsFile, NULL},
  2177. {"SAVECERT", CmdPrompt, _UU("CMD_MakeCert_PROMPT_SAVECERT"), CmdEvalNotEmpty, NULL},
  2178. {"SAVEKEY", CmdPrompt, _UU("CMD_MakeCert_PROMPT_SAVEKEY"), CmdEvalNotEmpty, NULL},
  2179. };
  2180. // Get the parameter list
  2181. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  2182. if (o == NULL)
  2183. {
  2184. return ERR_INVALID_PARAMETER;
  2185. }
  2186. if (IsEmptyStr(GetParamStr(o, "SIGNCERT")) == false && IsEmptyStr(GetParamStr(o, "SIGNKEY")) == false)
  2187. {
  2188. root_x = FileToXW(GetParamUniStr(o, "SIGNCERT"));
  2189. root_k = FileToKW(GetParamUniStr(o, "SIGNKEY"), true, NULL);
  2190. if (root_x == NULL || root_k == NULL || CheckXandK(root_x, root_k) == false)
  2191. {
  2192. ret = ERR_INTERNAL_ERROR;
  2193. c->Write(c, _UU("CMD_MakeCert_ERROR_SIGNKEY"));
  2194. }
  2195. }
  2196. if (ret == ERR_NO_ERROR)
  2197. {
  2198. buf = StrToBin(GetParamStr(o, "SERIAL"));
  2199. if (buf != NULL && buf->Size >= 1)
  2200. {
  2201. x_serial = NewXSerial(buf->Buf, buf->Size);
  2202. }
  2203. FreeBuf(buf);
  2204. n = NewName(GetParamUniStr(o, "CN"), GetParamUniStr(o, "O"), GetParamUniStr(o, "OU"),
  2205. GetParamUniStr(o, "C"), GetParamUniStr(o, "ST"), GetParamUniStr(o, "L"));
  2206. days = GetParamInt(o, "EXPIRES");
  2207. if (days == 0)
  2208. {
  2209. days = 3650;
  2210. }
  2211. RsaGen(&pri, &pub, 1024);
  2212. if (root_x == NULL)
  2213. {
  2214. x = NewRootX(pub, pri, n, days, x_serial);
  2215. }
  2216. else
  2217. {
  2218. x = NewX(pub, root_k, root_x, n, days, x_serial);
  2219. }
  2220. FreeXSerial(x_serial);
  2221. FreeName(n);
  2222. if (x == NULL)
  2223. {
  2224. ret = ERR_INTERNAL_ERROR;
  2225. c->Write(c, _UU("CMD_MakeCert_ERROR_GEN_FAILED"));
  2226. }
  2227. else
  2228. {
  2229. if (XToFileW(x, GetParamUniStr(o, "SAVECERT"), true) == false)
  2230. {
  2231. c->Write(c, _UU("CMD_SAVECERT_FAILED"));
  2232. }
  2233. else if (KToFileW(pri, GetParamUniStr(o, "SAVEKEY"), true, NULL) == false)
  2234. {
  2235. c->Write(c, _UU("CMD_SAVEKEY_FAILED"));
  2236. }
  2237. }
  2238. }
  2239. if (ret != ERR_NO_ERROR)
  2240. {
  2241. // Error has occurred
  2242. CmdPrintError(c, ret);
  2243. }
  2244. // Release of the parameter list
  2245. FreeParamValueList(o);
  2246. FreeX(root_x);
  2247. FreeK(root_k);
  2248. FreeX(x);
  2249. FreeK(pri);
  2250. FreeK(pub);
  2251. return ret;
  2252. }
  2253. // Certificate easy creation tool (2048 bit)
  2254. UINT PtMakeCert2048(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2255. {
  2256. LIST *o;
  2257. UINT ret = ERR_NO_ERROR;
  2258. X *x = NULL;
  2259. K *pub = NULL;
  2260. K *pri = NULL;
  2261. NAME *n;
  2262. X_SERIAL *x_serial = NULL;
  2263. BUF *buf;
  2264. UINT days;
  2265. X *root_x = NULL;
  2266. K *root_k = NULL;
  2267. // Parameter list that can be specified
  2268. CMD_EVAL_MIN_MAX minmax =
  2269. {
  2270. "CMD_MakeCert_EVAL_EXPIRES",
  2271. 0,
  2272. 10950,
  2273. };
  2274. PARAM args[] =
  2275. {
  2276. {"CN", CmdPrompt, _UU("CMD_MakeCert_PROMPT_CN"), NULL, NULL},
  2277. {"O", CmdPrompt, _UU("CMD_MakeCert_PROMPT_O"), NULL, NULL},
  2278. {"OU", CmdPrompt, _UU("CMD_MakeCert_PROMPT_OU"), NULL, NULL},
  2279. {"C", CmdPrompt, _UU("CMD_MakeCert_PROMPT_C"), NULL, NULL},
  2280. {"ST", CmdPrompt, _UU("CMD_MakeCert_PROMPT_ST"), NULL, NULL},
  2281. {"L", CmdPrompt, _UU("CMD_MakeCert_PROMPT_L"), NULL, NULL},
  2282. {"SERIAL", CmdPrompt, _UU("CMD_MakeCert_PROMPT_SERIAL"), NULL, NULL},
  2283. {"EXPIRES", CmdPrompt, _UU("CMD_MakeCert_PROMPT_EXPIRES"), CmdEvalMinMax, &minmax},
  2284. {"SIGNCERT", NULL, NULL, CmdEvalIsFile, NULL},
  2285. {"SIGNKEY", NULL, NULL, CmdEvalIsFile, NULL},
  2286. {"SAVECERT", CmdPrompt, _UU("CMD_MakeCert_PROMPT_SAVECERT"), CmdEvalNotEmpty, NULL},
  2287. {"SAVEKEY", CmdPrompt, _UU("CMD_MakeCert_PROMPT_SAVEKEY"), CmdEvalNotEmpty, NULL},
  2288. };
  2289. // Get the parameter list
  2290. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  2291. if (o == NULL)
  2292. {
  2293. return ERR_INVALID_PARAMETER;
  2294. }
  2295. if (IsEmptyStr(GetParamStr(o, "SIGNCERT")) == false && IsEmptyStr(GetParamStr(o, "SIGNKEY")) == false)
  2296. {
  2297. root_x = FileToXW(GetParamUniStr(o, "SIGNCERT"));
  2298. root_k = FileToKW(GetParamUniStr(o, "SIGNKEY"), true, NULL);
  2299. if (root_x == NULL || root_k == NULL || CheckXandK(root_x, root_k) == false)
  2300. {
  2301. ret = ERR_INTERNAL_ERROR;
  2302. c->Write(c, _UU("CMD_MakeCert_ERROR_SIGNKEY"));
  2303. }
  2304. }
  2305. if (ret == ERR_NO_ERROR)
  2306. {
  2307. buf = StrToBin(GetParamStr(o, "SERIAL"));
  2308. if (buf != NULL && buf->Size >= 1)
  2309. {
  2310. x_serial = NewXSerial(buf->Buf, buf->Size);
  2311. }
  2312. FreeBuf(buf);
  2313. n = NewName(GetParamUniStr(o, "CN"), GetParamUniStr(o, "O"), GetParamUniStr(o, "OU"),
  2314. GetParamUniStr(o, "C"), GetParamUniStr(o, "ST"), GetParamUniStr(o, "L"));
  2315. days = GetParamInt(o, "EXPIRES");
  2316. if (days == 0)
  2317. {
  2318. days = 3650;
  2319. }
  2320. RsaGen(&pri, &pub, 2048);
  2321. if (root_x == NULL)
  2322. {
  2323. x = NewRootX(pub, pri, n, days, x_serial);
  2324. }
  2325. else
  2326. {
  2327. x = NewX(pub, root_k, root_x, n, days, x_serial);
  2328. }
  2329. FreeXSerial(x_serial);
  2330. FreeName(n);
  2331. if (x == NULL)
  2332. {
  2333. ret = ERR_INTERNAL_ERROR;
  2334. c->Write(c, _UU("CMD_MakeCert_ERROR_GEN_FAILED"));
  2335. }
  2336. else
  2337. {
  2338. if (XToFileW(x, GetParamUniStr(o, "SAVECERT"), true) == false)
  2339. {
  2340. c->Write(c, _UU("CMD_SAVECERT_FAILED"));
  2341. }
  2342. else if (KToFileW(pri, GetParamUniStr(o, "SAVEKEY"), true, NULL) == false)
  2343. {
  2344. c->Write(c, _UU("CMD_SAVEKEY_FAILED"));
  2345. }
  2346. }
  2347. }
  2348. if (ret != ERR_NO_ERROR)
  2349. {
  2350. // Error has occurred
  2351. CmdPrintError(c, ret);
  2352. }
  2353. // Release of the parameter list
  2354. FreeParamValueList(o);
  2355. FreeX(root_x);
  2356. FreeK(root_k);
  2357. FreeX(x);
  2358. FreeK(pri);
  2359. FreeK(pub);
  2360. return ret;
  2361. }
  2362. // Client management tool main
  2363. void PcMain(PC *pc)
  2364. {
  2365. char prompt[MAX_SIZE];
  2366. wchar_t tmp[MAX_SIZE];
  2367. // Validate arguments
  2368. if (pc == NULL)
  2369. {
  2370. return;
  2371. }
  2372. // Display a message that the connection has been made
  2373. UniFormat(tmp, sizeof(tmp), _UU("CMD_VPNCMD_CLIENT_CONNECTED"),
  2374. pc->ServerName);
  2375. pc->Console->Write(pc->Console, tmp);
  2376. pc->Console->Write(pc->Console, L"");
  2377. while (true)
  2378. {
  2379. // Definition of command
  2380. CMD cmd[] =
  2381. {
  2382. {"About", PsAbout},
  2383. {"Check", PtCheck},
  2384. {"VersionGet", PcVersionGet},
  2385. {"PasswordSet", PcPasswordSet},
  2386. {"PasswordGet", PcPasswordGet},
  2387. {"CertList", PcCertList},
  2388. {"CertAdd", PcCertAdd},
  2389. {"CertDelete", PcCertDelete},
  2390. {"CertGet", PcCertGet},
  2391. {"SecureList", PcSecureList},
  2392. {"SecureSelect", PcSecureSelect},
  2393. {"SecureGet", PcSecureGet},
  2394. {"NicCreate", PcNicCreate},
  2395. {"NicDelete", PcNicDelete},
  2396. {"NicUpgrade", PcNicUpgrade},
  2397. {"NicGetSetting", PcNicGetSetting},
  2398. {"NicSetSetting", PcNicSetSetting},
  2399. {"NicEnable", PcNicEnable},
  2400. {"NicDisable", PcNicDisable},
  2401. {"NicList", PcNicList},
  2402. {"AccountList", PcAccountList},
  2403. {"AccountCreate", PcAccountCreate},
  2404. {"AccountSet", PcAccountSet},
  2405. {"AccountGet", PcAccountGet},
  2406. {"AccountDelete", PcAccountDelete},
  2407. {"AccountUsernameSet", PcAccountUsernameSet},
  2408. {"AccountAnonymousSet", PcAccountAnonymousSet},
  2409. {"AccountPasswordSet", PcAccountPasswordSet},
  2410. {"AccountCertSet", PcAccountCertSet},
  2411. {"AccountCertGet", PcAccountCertGet},
  2412. {"AccountEncryptDisable", PcAccountEncryptDisable},
  2413. {"AccountEncryptEnable", PcAccountEncryptEnable},
  2414. {"AccountCompressEnable", PcAccountCompressEnable},
  2415. {"AccountCompressDisable", PcAccountCompressDisable},
  2416. {"AccountProxyNone", PcAccountProxyNone},
  2417. {"AccountProxyHttp", PcAccountProxyHttp},
  2418. {"AccountProxySocks", PcAccountProxySocks},
  2419. {"AccountServerCertEnable", PcAccountServerCertEnable},
  2420. {"AccountServerCertDisable", PcAccountServerCertDisable},
  2421. {"AccountServerCertSet", PcAccountServerCertSet},
  2422. {"AccountServerCertDelete", PcAccountServerCertDelete},
  2423. {"AccountServerCertGet", PcAccountServerCertGet},
  2424. {"AccountDetailSet", PcAccountDetailSet},
  2425. {"AccountRename", PcAccountRename},
  2426. {"AccountConnect", PcAccountConnect},
  2427. {"AccountDisconnect", PcAccountDisconnect},
  2428. {"AccountStatusGet", PcAccountStatusGet},
  2429. {"AccountNicSet", PcAccountNicSet},
  2430. {"AccountStatusShow", PcAccountStatusShow},
  2431. {"AccountStatusHide", PcAccountStatusHide},
  2432. {"AccountSecureCertSet", PcAccountSecureCertSet},
  2433. {"AccountRetrySet", PcAccountRetrySet},
  2434. {"AccountStartupSet", PcAccountStartupSet},
  2435. {"AccountStartupRemove", PcAccountStartupRemove},
  2436. {"AccountExport", PcAccountExport},
  2437. {"AccountImport", PcAccountImport},
  2438. {"RemoteEnable", PcRemoteEnable},
  2439. {"RemoteDisable", PcRemoteDisable},
  2440. {"KeepEnable", PcKeepEnable},
  2441. {"KeepDisable", PcKeepDisable},
  2442. {"KeepSet", PcKeepSet},
  2443. {"KeepGet", PcKeepGet},
  2444. {"MakeCert", PtMakeCert},
  2445. {"MakeCert2048", PtMakeCert2048},
  2446. {"TrafficClient", PtTrafficClient},
  2447. {"TrafficServer", PtTrafficServer},
  2448. };
  2449. // Generate a prompt
  2450. StrCpy(prompt, sizeof(prompt), "VPN Client>");
  2451. if (DispatchNextCmdEx(pc->Console, pc->CmdLine, prompt, cmd, sizeof(cmd) / sizeof(cmd[0]), pc) == false)
  2452. {
  2453. break;
  2454. }
  2455. pc->LastError = pc->Console->RetCode;
  2456. if (pc->LastError == ERR_NO_ERROR && pc->Console->ConsoleType != CONSOLE_CSV)
  2457. {
  2458. pc->Console->Write(pc->Console, _UU("CMD_MSG_OK"));
  2459. pc->Console->Write(pc->Console, L"");
  2460. }
  2461. if (pc->CmdLine != NULL)
  2462. {
  2463. break;
  2464. }
  2465. }
  2466. }
  2467. // Retrieve the version information of VPN Client service
  2468. UINT PcVersionGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2469. {
  2470. LIST *o;
  2471. PC *pc = (PC *)param;
  2472. UINT ret = ERR_NO_ERROR;
  2473. RPC_CLIENT_VERSION t;
  2474. // Get the parameter list
  2475. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  2476. if (o == NULL)
  2477. {
  2478. return ERR_INVALID_PARAMETER;
  2479. }
  2480. // RPC call
  2481. Zero(&t, sizeof(t));
  2482. ret = CcGetClientVersion(pc->RemoteClient, &t);
  2483. if (ret == ERR_NO_ERROR)
  2484. {
  2485. wchar_t tmp[MAX_SIZE];
  2486. CT *ct;
  2487. // Success
  2488. ct = CtNewStandard();
  2489. StrToUni(tmp, sizeof(tmp), t.ClientProductName);
  2490. CtInsert(ct, _UU("CMD_VersionGet_1"), tmp);
  2491. StrToUni(tmp, sizeof(tmp), t.ClientVersionString);
  2492. CtInsert(ct, _UU("CMD_VersionGet_2"), tmp);
  2493. StrToUni(tmp, sizeof(tmp), t.ClientBuildInfoString);
  2494. CtInsert(ct, _UU("CMD_VersionGet_3"), tmp);
  2495. UniToStru(tmp, t.ProcessId);
  2496. CtInsert(ct, _UU("CMD_VersionGet_4"), tmp);
  2497. StrToUni(tmp, sizeof(tmp), OsTypeToStr(t.OsType));
  2498. CtInsert(ct, _UU("CMD_VersionGet_5"), tmp);
  2499. CtFree(ct, c);
  2500. }
  2501. if (ret != ERR_NO_ERROR)
  2502. {
  2503. // Error has occurred
  2504. CmdPrintError(c, ret);
  2505. }
  2506. // Release the parameter list
  2507. FreeParamValueList(o);
  2508. return ret;
  2509. }
  2510. // Set a password to connect to the VPN Client Service
  2511. UINT PcPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2512. {
  2513. LIST *o;
  2514. PC *pc = (PC *)param;
  2515. UINT ret = ERR_NO_ERROR;
  2516. RPC_CLIENT_PASSWORD t;
  2517. // Parameter list that can be specified
  2518. PARAM args[] =
  2519. {
  2520. {"[password]", CmdPromptChoosePassword, NULL, NULL, NULL},
  2521. {"REMOTEONLY", NULL, NULL, NULL, NULL},
  2522. };
  2523. // Get the parameter list
  2524. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  2525. if (o == NULL)
  2526. {
  2527. return ERR_INVALID_PARAMETER;
  2528. }
  2529. // RPC call
  2530. Zero(&t, sizeof(t));
  2531. StrCpy(t.Password, sizeof(t.Password), GetParamStr(o, "[password]"));
  2532. t.PasswordRemoteOnly = GetParamYes(o, "REMOTEONLY");
  2533. ret = CcSetPassword(pc->RemoteClient, &t);
  2534. if (ret == ERR_NO_ERROR)
  2535. {
  2536. // Success
  2537. }
  2538. if (ret != ERR_NO_ERROR)
  2539. {
  2540. // Error has occurred
  2541. CmdPrintError(c, ret);
  2542. }
  2543. // Release of the parameter list
  2544. FreeParamValueList(o);
  2545. return ret;
  2546. }
  2547. // Get the settings of the password to connect to the VPN Client service
  2548. UINT PcPasswordGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2549. {
  2550. LIST *o;
  2551. PC *pc = (PC *)param;
  2552. UINT ret = ERR_NO_ERROR;
  2553. RPC_CLIENT_PASSWORD_SETTING t;
  2554. // Get the parameter list
  2555. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  2556. if (o == NULL)
  2557. {
  2558. return ERR_INVALID_PARAMETER;
  2559. }
  2560. // RPC call
  2561. Zero(&t, sizeof(t));
  2562. ret = CcGetPasswordSetting(pc->RemoteClient, &t);
  2563. if (ret == ERR_NO_ERROR)
  2564. {
  2565. // Success
  2566. CT *ct = CtNewStandard();
  2567. CtInsert(ct, _UU("CMD_PasswordGet_1"),
  2568. t.IsPasswordPresented ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  2569. CtInsert(ct, _UU("CMD_PasswordGet_2"),
  2570. t.PasswordRemoteOnly ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  2571. CtFree(ct, c);
  2572. }
  2573. if (ret != ERR_NO_ERROR)
  2574. {
  2575. // Error has occurred
  2576. CmdPrintError(c, ret);
  2577. }
  2578. // Release the parameter list
  2579. FreeParamValueList(o);
  2580. return ret;
  2581. }
  2582. // Get the list of certificates of the trusted certification authority
  2583. UINT PcCertList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2584. {
  2585. LIST *o;
  2586. PC *pc = (PC *)param;
  2587. UINT ret = ERR_NO_ERROR;
  2588. RPC_CLIENT_ENUM_CA t;
  2589. // Get the parameter list
  2590. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  2591. if (o == NULL)
  2592. {
  2593. return ERR_INVALID_PARAMETER;
  2594. }
  2595. // RPC call
  2596. Zero(&t, sizeof(t));
  2597. ret = CcEnumCa(pc->RemoteClient, &t);
  2598. if (ret == ERR_NO_ERROR)
  2599. {
  2600. // Success
  2601. UINT i;
  2602. CT *ct = CtNewStandard();
  2603. for (i = 0;i < t.NumItem;i++)
  2604. {
  2605. wchar_t tmp[MAX_SIZE];
  2606. wchar_t tmp2[64];
  2607. RPC_CLIENT_ENUM_CA_ITEM *e = t.Items[i];
  2608. GetDateStrEx64(tmp, sizeof(tmp), SystemToLocal64(e->Expires), NULL);
  2609. UniToStru(tmp2, e->Key);
  2610. CtInsert(ct, _UU("CMD_CAList_COLUMN_ID"), tmp2);
  2611. CtInsert(ct, _UU("CM_CERT_COLUMN_1"), e->SubjectName);
  2612. CtInsert(ct, _UU("CM_CERT_COLUMN_2"), e->IssuerName);
  2613. CtInsert(ct, _UU("CM_CERT_COLUMN_3"), tmp);
  2614. if (i != (t.NumItem - 1))
  2615. {
  2616. CtInsert(ct, L"---", L"---");
  2617. }
  2618. }
  2619. CtFree(ct, c);
  2620. CiFreeClientEnumCa(&t);
  2621. }
  2622. if (ret != ERR_NO_ERROR)
  2623. {
  2624. // Error has occurred
  2625. CmdPrintError(c, ret);
  2626. }
  2627. // Release of the parameter list
  2628. FreeParamValueList(o);
  2629. return ret;
  2630. }
  2631. // Add a certificate of the trusted certification authority
  2632. UINT PcCertAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2633. {
  2634. LIST *o;
  2635. PC *pc = (PC *)param;
  2636. UINT ret = ERR_NO_ERROR;
  2637. RPC_CERT t;
  2638. X *x;
  2639. // Parameter list that can be specified
  2640. PARAM args[] =
  2641. {
  2642. {"[path]", CmdPrompt, _UU("CMD_CAAdd_PROMPT_PATH"), CmdEvalIsFile, NULL},
  2643. };
  2644. // Get the parameter list
  2645. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  2646. if (o == NULL)
  2647. {
  2648. return ERR_INVALID_PARAMETER;
  2649. }
  2650. x = FileToXW(GetParamUniStr(o, "[path]"));
  2651. if (x == NULL)
  2652. {
  2653. FreeParamValueList(o);
  2654. c->Write(c, _UU("CMD_MSG_LOAD_CERT_FAILED"));
  2655. return ERR_INVALID_PARAMETER;
  2656. }
  2657. // RPC call
  2658. Zero(&t, sizeof(t));
  2659. t.x = x;
  2660. ret = CcAddCa(pc->RemoteClient, &t);
  2661. if (ret == ERR_NO_ERROR)
  2662. {
  2663. // Success
  2664. }
  2665. if (ret != ERR_NO_ERROR)
  2666. {
  2667. // Error has occurred
  2668. CmdPrintError(c, ret);
  2669. }
  2670. FreeX(x);
  2671. // Release of the parameter list
  2672. FreeParamValueList(o);
  2673. return ret;
  2674. }
  2675. // Delete the certificate of the trusted certification authority
  2676. UINT PcCertDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2677. {
  2678. LIST *o;
  2679. PC *pc = (PC *)param;
  2680. UINT ret = ERR_NO_ERROR;
  2681. RPC_CLIENT_DELETE_CA t;
  2682. // Parameter list that can be specified
  2683. PARAM args[] =
  2684. {
  2685. {"[id]", CmdPrompt, _UU("CMD_CADelete_PROMPT_ID"), CmdEvalNotEmpty, NULL},
  2686. };
  2687. // Get the parameter list
  2688. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  2689. if (o == NULL)
  2690. {
  2691. return ERR_INVALID_PARAMETER;
  2692. }
  2693. // RPC call
  2694. Zero(&t, sizeof(t));
  2695. t.Key = GetParamInt(o, "[id]");
  2696. ret = CcDeleteCa(pc->RemoteClient, &t);
  2697. if (ret == ERR_NO_ERROR)
  2698. {
  2699. // Success
  2700. }
  2701. if (ret != ERR_NO_ERROR)
  2702. {
  2703. // Error has occurred
  2704. CmdPrintError(c, ret);
  2705. }
  2706. // Release of the parameter list
  2707. FreeParamValueList(o);
  2708. return ret;
  2709. }
  2710. // Get the certificate of the trusted certification authority
  2711. UINT PcCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2712. {
  2713. LIST *o;
  2714. PC *pc = (PC *)param;
  2715. UINT ret = ERR_NO_ERROR;
  2716. RPC_GET_CA t;
  2717. // Parameter list that can be specified
  2718. PARAM args[] =
  2719. {
  2720. {"[id]", CmdPrompt, _UU("CMD_CAGet_PROMPT_ID"), CmdEvalNotEmpty, NULL},
  2721. {"SAVECERT", CmdPrompt, _UU("CMD_CAGet_PROMPT_SAVECERT"), CmdEvalNotEmpty, NULL},
  2722. };
  2723. // Get the parameter list
  2724. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  2725. if (o == NULL)
  2726. {
  2727. return ERR_INVALID_PARAMETER;
  2728. }
  2729. // RPC call
  2730. Zero(&t, sizeof(t));
  2731. t.Key = GetParamInt(o, "[id]");
  2732. ret = CcGetCa(pc->RemoteClient, &t);
  2733. if (ret == ERR_NO_ERROR)
  2734. {
  2735. // Success
  2736. if (XToFileW(t.x, GetParamUniStr(o, "SAVECERT"), true))
  2737. {
  2738. // Success
  2739. }
  2740. else
  2741. {
  2742. // Failure
  2743. ret = ERR_INTERNAL_ERROR;
  2744. c->Write(c, _UU("CMD_MSG_SAVE_CERT_FAILED"));
  2745. }
  2746. CiFreeGetCa(&t);
  2747. }
  2748. if (ret != ERR_NO_ERROR)
  2749. {
  2750. // Error has occurred
  2751. CmdPrintError(c, ret);
  2752. }
  2753. // Release of the parameter list
  2754. FreeParamValueList(o);
  2755. return ret;
  2756. }
  2757. // Get the list of the type of smart card that can be used
  2758. UINT PcSecureList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2759. {
  2760. LIST *o;
  2761. PC *pc = (PC *)param;
  2762. UINT ret = ERR_NO_ERROR;
  2763. RPC_CLIENT_ENUM_SECURE t;
  2764. // Get the parameter list
  2765. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  2766. if (o == NULL)
  2767. {
  2768. return ERR_INVALID_PARAMETER;
  2769. }
  2770. // RPC call
  2771. Zero(&t, sizeof(t));
  2772. ret = CcEnumSecure(pc->RemoteClient, &t);
  2773. if (ret == ERR_NO_ERROR)
  2774. {
  2775. CT *ct;
  2776. UINT i;
  2777. wchar_t tmp1[MAX_SIZE];
  2778. wchar_t tmp2[MAX_SIZE];
  2779. wchar_t tmp4[MAX_SIZE];
  2780. wchar_t *tmp3;
  2781. // Success
  2782. ct = CtNew();
  2783. CtInsertColumn(ct, _UU("SEC_COLUMN1"), false);
  2784. CtInsertColumn(ct, _UU("SEC_COLUMN2"), false);
  2785. CtInsertColumn(ct, _UU("SEC_COLUMN3"), false);
  2786. CtInsertColumn(ct, _UU("SEC_COLUMN4"), false);
  2787. for (i = 0;i < t.NumItem;i++)
  2788. {
  2789. RPC_CLIENT_ENUM_SECURE_ITEM *e = t.Items[i];
  2790. // ID
  2791. UniToStru(tmp1, e->DeviceId);
  2792. // Device name
  2793. StrToUni(tmp2, sizeof(tmp2), e->DeviceName);
  2794. // Type
  2795. tmp3 = (e->Type == SECURE_IC_CARD) ? _UU("SEC_SMART_CARD") : _UU("SEC_USB_TOKEN");
  2796. // Manufacturer
  2797. StrToUni(tmp4, sizeof(tmp4), e->Manufacturer);
  2798. CtInsert(ct, tmp1, tmp2, tmp3, tmp4);
  2799. }
  2800. CtFreeEx(ct, c, true);
  2801. CiFreeClientEnumSecure(&t);
  2802. }
  2803. if (ret != ERR_NO_ERROR)
  2804. {
  2805. // Error has occurred
  2806. CmdPrintError(c, ret);
  2807. }
  2808. // Release of the parameter list
  2809. FreeParamValueList(o);
  2810. return ret;
  2811. }
  2812. // Select the type of smart card to be used
  2813. UINT PcSecureSelect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2814. {
  2815. LIST *o;
  2816. PC *pc = (PC *)param;
  2817. UINT ret = ERR_NO_ERROR;
  2818. RPC_USE_SECURE t;
  2819. // Parameter list that can be specified
  2820. PARAM args[] =
  2821. {
  2822. {"[id]", CmdPrompt, _UU("CMD_SecureSelect_PROMPT_ID"), NULL, NULL},
  2823. };
  2824. // Get the parameter list
  2825. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  2826. if (o == NULL)
  2827. {
  2828. return ERR_INVALID_PARAMETER;
  2829. }
  2830. // RPC call
  2831. Zero(&t, sizeof(t));
  2832. t.DeviceId = GetParamInt(o, "[id]");
  2833. ret = CcUseSecure(pc->RemoteClient, &t);
  2834. if (ret == ERR_NO_ERROR)
  2835. {
  2836. // Success
  2837. }
  2838. if (ret != ERR_NO_ERROR)
  2839. {
  2840. // Error has occurred
  2841. CmdPrintError(c, ret);
  2842. }
  2843. // Release of the parameter list
  2844. FreeParamValueList(o);
  2845. return ret;
  2846. }
  2847. // Get the type ID of smart card to be used
  2848. UINT PcSecureGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2849. {
  2850. LIST *o;
  2851. PC *pc = (PC *)param;
  2852. UINT ret = ERR_NO_ERROR;
  2853. RPC_USE_SECURE t;
  2854. // Get the parameter list
  2855. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  2856. if (o == NULL)
  2857. {
  2858. return ERR_INVALID_PARAMETER;
  2859. }
  2860. // RPC call
  2861. Zero(&t, sizeof(t));
  2862. ret = CcGetUseSecure(pc->RemoteClient, &t);
  2863. if (ret == ERR_NO_ERROR)
  2864. {
  2865. // Success
  2866. wchar_t tmp[MAX_SIZE];
  2867. if (t.DeviceId != 0)
  2868. {
  2869. UniFormat(tmp, sizeof(tmp), _UU("CMD_SecureGet_Print"), t.DeviceId);
  2870. }
  2871. else
  2872. {
  2873. UniStrCpy(tmp, sizeof(tmp), _UU("CMD_SecureGet_NoPrint"));
  2874. }
  2875. c->Write(c, tmp);
  2876. }
  2877. if (ret != ERR_NO_ERROR)
  2878. {
  2879. // Error has occurred
  2880. CmdPrintError(c, ret);
  2881. }
  2882. // Release of the parameter list
  2883. FreeParamValueList(o);
  2884. return ret;
  2885. }
  2886. // Create a new virtual LAN card
  2887. UINT PcNicCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2888. {
  2889. LIST *o;
  2890. PC *pc = (PC *)param;
  2891. UINT ret = ERR_NO_ERROR;
  2892. RPC_CLIENT_CREATE_VLAN t;
  2893. // Parameter list that can be specified
  2894. PARAM args[] =
  2895. {
  2896. {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  2897. };
  2898. // Get the parameter list
  2899. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  2900. if (o == NULL)
  2901. {
  2902. return ERR_INVALID_PARAMETER;
  2903. }
  2904. // RPC call
  2905. Zero(&t, sizeof(t));
  2906. StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));
  2907. ret = CcCreateVLan(pc->RemoteClient, &t);
  2908. if (ret == ERR_NO_ERROR)
  2909. {
  2910. // Success
  2911. }
  2912. if (ret != ERR_NO_ERROR)
  2913. {
  2914. // Error has occurred
  2915. CmdPrintError(c, ret);
  2916. }
  2917. // Release of the parameter list
  2918. FreeParamValueList(o);
  2919. return ret;
  2920. }
  2921. // Delete the virtual LAN card
  2922. UINT PcNicDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2923. {
  2924. LIST *o;
  2925. PC *pc = (PC *)param;
  2926. UINT ret = ERR_NO_ERROR;
  2927. RPC_CLIENT_CREATE_VLAN t;
  2928. // Parameter list that can be specified
  2929. PARAM args[] =
  2930. {
  2931. {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  2932. };
  2933. // Get the parameter list
  2934. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  2935. if (o == NULL)
  2936. {
  2937. return ERR_INVALID_PARAMETER;
  2938. }
  2939. // RPC call
  2940. Zero(&t, sizeof(t));
  2941. StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));
  2942. ret = CcDeleteVLan(pc->RemoteClient, &t);
  2943. if (ret == ERR_NO_ERROR)
  2944. {
  2945. // Success
  2946. }
  2947. if (ret != ERR_NO_ERROR)
  2948. {
  2949. // Error has occurred
  2950. CmdPrintError(c, ret);
  2951. }
  2952. // Release of the parameter list
  2953. FreeParamValueList(o);
  2954. return ret;
  2955. }
  2956. // Upgrading the device driver of the virtual LAN card
  2957. UINT PcNicUpgrade(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2958. {
  2959. LIST *o;
  2960. PC *pc = (PC *)param;
  2961. UINT ret = ERR_NO_ERROR;
  2962. RPC_CLIENT_CREATE_VLAN t;
  2963. // Parameter list that can be specified
  2964. PARAM args[] =
  2965. {
  2966. {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  2967. };
  2968. // Get the parameter list
  2969. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  2970. if (o == NULL)
  2971. {
  2972. return ERR_INVALID_PARAMETER;
  2973. }
  2974. // RPC call
  2975. Zero(&t, sizeof(t));
  2976. StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));
  2977. ret = CcUpgradeVLan(pc->RemoteClient, &t);
  2978. if (ret == ERR_NO_ERROR)
  2979. {
  2980. // Success
  2981. }
  2982. if (ret != ERR_NO_ERROR)
  2983. {
  2984. // Error has occurred
  2985. CmdPrintError(c, ret);
  2986. }
  2987. // Release of the parameter list
  2988. FreeParamValueList(o);
  2989. return ret;
  2990. }
  2991. // Get the settings of the virtual LAN card
  2992. UINT PcNicGetSetting(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  2993. {
  2994. LIST *o;
  2995. PC *pc = (PC *)param;
  2996. UINT ret = ERR_NO_ERROR;
  2997. RPC_CLIENT_GET_VLAN t;
  2998. // Parameter list that can be specified
  2999. PARAM args[] =
  3000. {
  3001. {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  3002. };
  3003. // Get the parameter list
  3004. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3005. if (o == NULL)
  3006. {
  3007. return ERR_INVALID_PARAMETER;
  3008. }
  3009. // RPC call
  3010. Zero(&t, sizeof(t));
  3011. StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));
  3012. ret = CcGetVLan(pc->RemoteClient, &t);
  3013. if (ret == ERR_NO_ERROR)
  3014. {
  3015. // Success
  3016. CT *ct = CtNewStandard();
  3017. wchar_t tmp[MAX_SIZE];
  3018. StrToUni(tmp, sizeof(tmp), t.DeviceName);
  3019. CtInsert(ct, _UU("CMD_NicGetSetting_1"), tmp);
  3020. CtInsert(ct, _UU("CMD_NicGetSetting_2"), t.Enabled ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  3021. StrToUni(tmp, sizeof(tmp), t.MacAddress);
  3022. CtInsert(ct, _UU("CMD_NicGetSetting_3"), tmp);
  3023. StrToUni(tmp, sizeof(tmp), t.Version);
  3024. CtInsert(ct, _UU("CMD_NicGetSetting_4"), tmp);
  3025. StrToUni(tmp, sizeof(tmp), t.FileName);
  3026. CtInsert(ct, _UU("CMD_NicGetSetting_5"), tmp);
  3027. StrToUni(tmp, sizeof(tmp), t.Guid);
  3028. CtInsert(ct, _UU("CMD_NicGetSetting_6"), tmp);
  3029. CtFree(ct, c);
  3030. }
  3031. if (ret != ERR_NO_ERROR)
  3032. {
  3033. // Error has occurred
  3034. CmdPrintError(c, ret);
  3035. }
  3036. // Release of the parameter list
  3037. FreeParamValueList(o);
  3038. return ret;
  3039. }
  3040. // Change the settings for the virtual LAN card
  3041. UINT PcNicSetSetting(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3042. {
  3043. LIST *o;
  3044. PC *pc = (PC *)param;
  3045. UINT ret = ERR_NO_ERROR;
  3046. RPC_CLIENT_SET_VLAN t;
  3047. UCHAR mac_address[6];
  3048. BUF *b;
  3049. // Parameter list that can be specified
  3050. PARAM args[] =
  3051. {
  3052. {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  3053. {"MAC", CmdPrompt, _UU("CMD_NicSetSetting_PROMPT_MAC"), CmdEvalNotEmpty, NULL},
  3054. };
  3055. // Get the parameter list
  3056. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3057. if (o == NULL)
  3058. {
  3059. return ERR_INVALID_PARAMETER;
  3060. }
  3061. // Inspect the MAC address
  3062. Zero(mac_address, sizeof(mac_address));
  3063. b = StrToBin(GetParamStr(o, "MAC"));
  3064. if (b != NULL && b->Size == 6)
  3065. {
  3066. Copy(mac_address, b->Buf, 6);
  3067. }
  3068. FreeBuf(b);
  3069. if (IsZero(mac_address, 6))
  3070. {
  3071. // MAC address is invalid
  3072. FreeParamValueList(o);
  3073. CmdPrintError(c, ERR_INVALID_PARAMETER);
  3074. return ERR_INVALID_PARAMETER;
  3075. }
  3076. // RPC call
  3077. Zero(&t, sizeof(t));
  3078. StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));
  3079. NormalizeMacAddress(t.MacAddress, sizeof(t.MacAddress), GetParamStr(o, "MAC"));
  3080. ret = CcSetVLan(pc->RemoteClient, &t);
  3081. if (ret == ERR_NO_ERROR)
  3082. {
  3083. // Success
  3084. }
  3085. if (ret != ERR_NO_ERROR)
  3086. {
  3087. // Error has occurred
  3088. CmdPrintError(c, ret);
  3089. }
  3090. // Release of the parameter list
  3091. FreeParamValueList(o);
  3092. return ret;
  3093. }
  3094. // Enable the virtual LAN card
  3095. UINT PcNicEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3096. {
  3097. LIST *o;
  3098. PC *pc = (PC *)param;
  3099. UINT ret = ERR_NO_ERROR;
  3100. RPC_CLIENT_CREATE_VLAN t;
  3101. // Parameter list that can be specified
  3102. PARAM args[] =
  3103. {
  3104. {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  3105. };
  3106. // Get the parameter list
  3107. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3108. if (o == NULL)
  3109. {
  3110. return ERR_INVALID_PARAMETER;
  3111. }
  3112. // RPC call
  3113. Zero(&t, sizeof(t));
  3114. StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));
  3115. ret = CcEnableVLan(pc->RemoteClient, &t);
  3116. if (ret == ERR_NO_ERROR)
  3117. {
  3118. // Success
  3119. }
  3120. if (ret != ERR_NO_ERROR)
  3121. {
  3122. // Error has occurred
  3123. CmdPrintError(c, ret);
  3124. }
  3125. // Release of the parameter list
  3126. FreeParamValueList(o);
  3127. return ret;
  3128. }
  3129. // Disable the virtual LAN card
  3130. UINT PcNicDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3131. {
  3132. LIST *o;
  3133. PC *pc = (PC *)param;
  3134. UINT ret = ERR_NO_ERROR;
  3135. RPC_CLIENT_CREATE_VLAN t;
  3136. // Parameter list that can be specified
  3137. PARAM args[] =
  3138. {
  3139. {"[name]", CmdPrompt, _UU("CMD_NicCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  3140. };
  3141. // Get the parameter list
  3142. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3143. if (o == NULL)
  3144. {
  3145. return ERR_INVALID_PARAMETER;
  3146. }
  3147. // RPC call
  3148. Zero(&t, sizeof(t));
  3149. StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "[name]"));
  3150. ret = CcDisableVLan(pc->RemoteClient, &t);
  3151. if (ret == ERR_NO_ERROR)
  3152. {
  3153. // Success
  3154. }
  3155. if (ret != ERR_NO_ERROR)
  3156. {
  3157. // Error has occurred
  3158. CmdPrintError(c, ret);
  3159. }
  3160. // Release of the parameter list
  3161. FreeParamValueList(o);
  3162. return ret;
  3163. }
  3164. // Get the Virtual LAN card list
  3165. UINT PcNicList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3166. {
  3167. LIST *o;
  3168. PC *pc = (PC *)param;
  3169. UINT ret = ERR_NO_ERROR;
  3170. RPC_CLIENT_ENUM_VLAN t;
  3171. // Get the parameter list
  3172. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  3173. if (o == NULL)
  3174. {
  3175. return ERR_INVALID_PARAMETER;
  3176. }
  3177. // RPC call
  3178. Zero(&t, sizeof(t));
  3179. ret = CcEnumVLan(pc->RemoteClient, &t);
  3180. if (ret == ERR_NO_ERROR)
  3181. {
  3182. CT *ct;
  3183. UINT i;
  3184. // Success
  3185. ct = CtNew();
  3186. CtInsertColumn(ct, _UU("CM_VLAN_COLUMN_1"), false);
  3187. CtInsertColumn(ct, _UU("CM_VLAN_COLUMN_2"), false);
  3188. CtInsertColumn(ct, _UU("CM_VLAN_COLUMN_3"), false);
  3189. CtInsertColumn(ct, _UU("CM_VLAN_COLUMN_4"), false);
  3190. for (i = 0;i < t.NumItem;i++)
  3191. {
  3192. wchar_t name[MAX_SIZE];
  3193. wchar_t mac[MAX_SIZE];
  3194. wchar_t ver[MAX_SIZE];
  3195. wchar_t *status;
  3196. RPC_CLIENT_ENUM_VLAN_ITEM *v = t.Items[i];
  3197. // Device name
  3198. StrToUni(name, sizeof(name), v->DeviceName);
  3199. // State
  3200. status = v->Enabled ? _UU("CM_VLAN_ENABLED") : _UU("CM_VLAN_DISABLED");
  3201. // MAC address
  3202. StrToUni(mac, sizeof(mac), v->MacAddress);
  3203. // Version
  3204. StrToUni(ver, sizeof(ver), v->Version);
  3205. CtInsert(ct,
  3206. name, status, mac, ver);
  3207. }
  3208. CtFreeEx(ct, c, true);
  3209. }
  3210. if (ret != ERR_NO_ERROR)
  3211. {
  3212. // Error has occurred
  3213. CmdPrintError(c, ret);
  3214. }
  3215. CiFreeClientEnumVLan(&t);
  3216. // Release of the parameter list
  3217. FreeParamValueList(o);
  3218. return ret;
  3219. }
  3220. // Get the protocol name string from ID
  3221. wchar_t *GetProtocolName(UINT n)
  3222. {
  3223. switch (n)
  3224. {
  3225. case PROXY_DIRECT:
  3226. return _UU("PROTO_DIRECT_TCP");
  3227. case PROXY_HTTP:
  3228. return _UU("PROTO_HTTP_PROXY");
  3229. case PROXY_SOCKS:
  3230. return _UU("PROTO_SOCKS_PROXY");
  3231. }
  3232. return _UU("PROTO_UNKNOWN");
  3233. }
  3234. // Get the connection settings list
  3235. UINT PcAccountList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3236. {
  3237. LIST *o;
  3238. PC *pc = (PC *)param;
  3239. UINT ret = ERR_NO_ERROR;
  3240. RPC_CLIENT_ENUM_ACCOUNT t;
  3241. // Get the parameter list
  3242. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  3243. if (o == NULL)
  3244. {
  3245. return ERR_INVALID_PARAMETER;
  3246. }
  3247. // RPC call
  3248. Zero(&t, sizeof(t));
  3249. ret = CcEnumAccount(pc->RemoteClient, &t);
  3250. if (ret == ERR_NO_ERROR)
  3251. {
  3252. UINT i;
  3253. CT *ct;
  3254. // Success
  3255. ct = CtNew();
  3256. CtInsertColumn(ct, _UU("CM_ACCOUNT_COLUMN_1"), false);
  3257. CtInsertColumn(ct, _UU("CM_ACCOUNT_COLUMN_2"), false);
  3258. CtInsertColumn(ct, _UU("CM_ACCOUNT_COLUMN_3"), false);
  3259. CtInsertColumn(ct, _UU("CM_ACCOUNT_COLUMN_3_2"), false);
  3260. CtInsertColumn(ct, _UU("CM_ACCOUNT_COLUMN_4"), false);
  3261. for (i = 0;i < t.NumItem;i++)
  3262. {
  3263. RPC_CLIENT_ENUM_ACCOUNT_ITEM *e = t.Items[i];
  3264. wchar_t tmp[MAX_SIZE];
  3265. wchar_t tmp2[MAX_SIZE];
  3266. wchar_t tmp4[MAX_SIZE];
  3267. IP ip;
  3268. char ip_str[MAX_SIZE];
  3269. // Special treatment for IPv6 addresses
  3270. if (StrToIP6(&ip, e->ServerName) && StartWith(e->ServerName, "[") == false)
  3271. {
  3272. Format(ip_str, sizeof(ip_str),
  3273. "[%s]", e->ServerName);
  3274. }
  3275. else
  3276. {
  3277. StrCpy(ip_str, sizeof(ip_str), e->ServerName);
  3278. }
  3279. if (e->Port == 0)
  3280. {
  3281. // Port number unknown
  3282. UniFormat(tmp2, sizeof(tmp2), L"%S (%s)", ip_str, GetProtocolName(e->ProxyType));
  3283. }
  3284. else
  3285. {
  3286. // Port number are also shown
  3287. UniFormat(tmp2, sizeof(tmp2), L"%S:%u (%s)", ip_str, e->Port, GetProtocolName(e->ProxyType));
  3288. }
  3289. // Virtual HUB name
  3290. StrToUni(tmp4, sizeof(tmp4), e->HubName);
  3291. // Add
  3292. StrToUni(tmp, sizeof(tmp), e->DeviceName);
  3293. CtInsert(ct,
  3294. e->AccountName,
  3295. e->Active == false ? _UU("CM_ACCOUNT_OFFLINE") :
  3296. (e->Connected ? _UU("CM_ACCOUNT_ONLINE") : _UU("CM_ACCOUNT_CONNECTING")),
  3297. tmp2, tmp4,
  3298. tmp);
  3299. }
  3300. CtFreeEx(ct, c, true);
  3301. }
  3302. CiFreeClientEnumAccount(&t);
  3303. if (ret != ERR_NO_ERROR)
  3304. {
  3305. // Error has occurred
  3306. CmdPrintError(c, ret);
  3307. }
  3308. // Release of the parameter list
  3309. FreeParamValueList(o);
  3310. return ret;
  3311. }
  3312. // Create new connection settings
  3313. UINT PcAccountCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3314. {
  3315. LIST *o;
  3316. PC *pc = (PC *)param;
  3317. UINT ret = ERR_NO_ERROR;
  3318. RPC_CLIENT_CREATE_ACCOUNT t;
  3319. UINT port = 443;
  3320. char *host = NULL;
  3321. // Parameter list that can be specified
  3322. PARAM args[] =
  3323. {
  3324. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  3325. {"SERVER", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Server"), CmdEvalHostAndPort, NULL},
  3326. {"HUB", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Hub"), CmdEvalSafe, NULL},
  3327. {"USERNAME", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Username"), CmdEvalNotEmpty, NULL},
  3328. {"NICNAME", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Nicname"), CmdEvalNotEmpty, NULL},
  3329. };
  3330. // Get the parameter list
  3331. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3332. if (o == NULL)
  3333. {
  3334. return ERR_INVALID_PARAMETER;
  3335. }
  3336. ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 443);
  3337. // RPC call
  3338. Zero(&t, sizeof(t));
  3339. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  3340. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  3341. t.ClientOption->Port = port;
  3342. StrCpy(t.ClientOption->Hostname, sizeof(t.ClientOption->Hostname), host);
  3343. StrCpy(t.ClientOption->HubName, sizeof(t.ClientOption->HubName), GetParamStr(o, "HUB"));
  3344. t.ClientOption->NumRetry = INFINITE;
  3345. t.ClientOption->RetryInterval = 15;
  3346. t.ClientOption->MaxConnection = 1;
  3347. t.ClientOption->UseEncrypt = true;
  3348. t.ClientOption->AdditionalConnectionInterval = 1;
  3349. StrCpy(t.ClientOption->DeviceName, sizeof(t.ClientOption->DeviceName), GetParamStr(o, "NICNAME"));
  3350. t.ClientAuth = ZeroMalloc(sizeof(CLIENT_AUTH));
  3351. t.ClientAuth->AuthType = CLIENT_AUTHTYPE_ANONYMOUS;
  3352. StrCpy(t.ClientAuth->Username, sizeof(t.ClientAuth->Username), GetParamStr(o, "USERNAME"));
  3353. Free(host);
  3354. ret = CcCreateAccount(pc->RemoteClient, &t);
  3355. if (ret == ERR_NO_ERROR)
  3356. {
  3357. // Success
  3358. }
  3359. CiFreeClientCreateAccount(&t);
  3360. if (ret != ERR_NO_ERROR)
  3361. {
  3362. // Error has occurred
  3363. CmdPrintError(c, ret);
  3364. }
  3365. // Release of the parameter list
  3366. FreeParamValueList(o);
  3367. return ret;
  3368. }
  3369. // Set the destination of the connection settings
  3370. UINT PcAccountSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3371. {
  3372. LIST *o;
  3373. PC *pc = (PC *)param;
  3374. UINT ret = ERR_NO_ERROR;
  3375. RPC_CLIENT_GET_ACCOUNT t;
  3376. char *host = NULL;
  3377. UINT port = 443;
  3378. // Parameter list that can be specified
  3379. PARAM args[] =
  3380. {
  3381. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  3382. {"SERVER", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Server"), CmdEvalHostAndPort, NULL},
  3383. {"HUB", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Hub"), CmdEvalSafe, NULL},
  3384. };
  3385. // Get the parameter list
  3386. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3387. if (o == NULL)
  3388. {
  3389. return ERR_INVALID_PARAMETER;
  3390. }
  3391. // RPC call
  3392. Zero(&t, sizeof(t));
  3393. ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 443);
  3394. Zero(&t, sizeof(t));
  3395. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  3396. ret = CcGetAccount(pc->RemoteClient, &t);
  3397. if (ret == ERR_NO_ERROR)
  3398. {
  3399. RPC_CLIENT_CREATE_ACCOUNT c;
  3400. // Success
  3401. t.ClientOption->Port = port;
  3402. StrCpy(t.ClientOption->Hostname, sizeof(t.ClientOption->Hostname), host);
  3403. StrCpy(t.ClientOption->HubName, sizeof(t.ClientOption->HubName), GetParamStr(o, "HUB"));
  3404. Zero(&c, sizeof(c));
  3405. c.ClientAuth = t.ClientAuth;
  3406. c.ClientOption = t.ClientOption;
  3407. c.CheckServerCert = t.CheckServerCert;
  3408. c.ServerCert = t.ServerCert;
  3409. c.StartupAccount = t.StartupAccount;
  3410. ret = CcSetAccount(pc->RemoteClient, &c);
  3411. }
  3412. if (ret != ERR_NO_ERROR)
  3413. {
  3414. // Error has occurred
  3415. CmdPrintError(c, ret);
  3416. }
  3417. CiFreeClientGetAccount(&t);
  3418. // Release of the parameter list
  3419. FreeParamValueList(o);
  3420. Free(host);
  3421. return ret;
  3422. }
  3423. // Get the configuration of the connection settings
  3424. UINT PcAccountGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3425. {
  3426. LIST *o;
  3427. PC *pc = (PC *)param;
  3428. UINT ret = ERR_NO_ERROR;
  3429. RPC_CLIENT_GET_ACCOUNT t;
  3430. // Parameter list that can be specified
  3431. PARAM args[] =
  3432. {
  3433. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  3434. };
  3435. // Get the parameter list
  3436. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3437. if (o == NULL)
  3438. {
  3439. return ERR_INVALID_PARAMETER;
  3440. }
  3441. // RPC call
  3442. Zero(&t, sizeof(t));
  3443. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  3444. ret = CcGetAccount(pc->RemoteClient, &t);
  3445. if (ret == ERR_NO_ERROR)
  3446. {
  3447. // Show the contents of the connection settings
  3448. wchar_t tmp[MAX_SIZE];
  3449. CT *ct = CtNewStandard();
  3450. // Connection settings name
  3451. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NAME"), t.ClientOption->AccountName);
  3452. // Host name of the destination VPN Server
  3453. StrToUni(tmp, sizeof(tmp), t.ClientOption->Hostname);
  3454. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_HOSTNAME"), tmp);
  3455. // The port number to connect to VPN Server
  3456. UniToStru(tmp, t.ClientOption->Port);
  3457. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PORT"), tmp);
  3458. // Virtual HUB name of the destination VPN Server
  3459. StrToUni(tmp, sizeof(tmp), t.ClientOption->HubName);
  3460. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_HUBNAME"), tmp);
  3461. // Type of proxy server to go through
  3462. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_TYPE"), GetProxyTypeStr(t.ClientOption->ProxyType));
  3463. if (t.ClientOption->ProxyType != PROXY_DIRECT)
  3464. {
  3465. // Host name of the proxy server
  3466. StrToUni(tmp, sizeof(tmp), t.ClientOption->ProxyName);
  3467. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_HOSTNAME"), tmp);
  3468. // Port number of the proxy server
  3469. UniToStru(tmp, t.ClientOption->ProxyPort);
  3470. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_PORT"), tmp);
  3471. // User name of the proxy server
  3472. StrToUni(tmp, sizeof(tmp), t.ClientOption->ProxyUsername);
  3473. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_USERNAME"), tmp);
  3474. }
  3475. // Verify the server certificate
  3476. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_SERVER_CERT_USE"),
  3477. t.CheckServerCert ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  3478. // Registered specific certificate
  3479. if (t.ServerCert != NULL)
  3480. {
  3481. GetAllNameFromX(tmp, sizeof(tmp), t.ServerCert);
  3482. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_SERVER_CERT_NAME"), tmp);
  3483. }
  3484. // Device name to be used for the connection
  3485. StrToUni(tmp, sizeof(tmp), t.ClientOption->DeviceName);
  3486. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_DEVICE_NAME"), tmp);
  3487. // Authentication type
  3488. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_AUTH_TYPE"), GetClientAuthTypeStr(t.ClientAuth->AuthType));
  3489. // User name
  3490. StrToUni(tmp, sizeof(tmp), t.ClientAuth->Username);
  3491. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_AUTH_USERNAME"), tmp);
  3492. if (t.ClientAuth->AuthType == CLIENT_AUTHTYPE_CERT)
  3493. {
  3494. if (t.ClientAuth->ClientX != NULL)
  3495. {
  3496. // Client certificate name
  3497. GetAllNameFromX(tmp, sizeof(tmp), t.ClientAuth->ClientX);
  3498. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_AUTH_CERT_NAME"), tmp);
  3499. }
  3500. }
  3501. // Number of TCP connections to be used for VPN communication
  3502. UniToStru(tmp, t.ClientOption->MaxConnection);
  3503. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NUMTCP"), tmp);
  3504. // Establishment interval of each TCP connection
  3505. UniToStru(tmp, t.ClientOption->AdditionalConnectionInterval);
  3506. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_TCP_INTERVAL"), tmp);
  3507. // Life span of each TCP connection
  3508. if (t.ClientOption->ConnectionDisconnectSpan != 0)
  3509. {
  3510. UniToStru(tmp, t.ClientOption->ConnectionDisconnectSpan);
  3511. }
  3512. else
  3513. {
  3514. UniStrCpy(tmp, sizeof(tmp), _UU("CMD_MSG_INFINITE"));
  3515. }
  3516. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_TCP_TTL"), tmp);
  3517. // Use of half-duplex mode
  3518. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_TCP_HALF"),
  3519. t.ClientOption->HalfConnection ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  3520. // Encryption by SSL
  3521. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_ENCRYPT"),
  3522. t.ClientOption->UseEncrypt ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  3523. // Data compression
  3524. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_COMPRESS"),
  3525. t.ClientOption->UseCompress ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  3526. // Connect in bridge / router mode
  3527. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_BRIDGE_ROUTER"),
  3528. t.ClientOption->RequireBridgeRoutingMode ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  3529. // Connect in monitoring mode
  3530. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_MONITOR"),
  3531. t.ClientOption->RequireMonitorMode ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  3532. // Not to rewrite the routing table
  3533. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NO_TRACKING"),
  3534. t.ClientOption->NoRoutingTracking ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  3535. // Disable the QoS control
  3536. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_QOS_DISABLE"),
  3537. t.ClientOption->DisableQoS ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  3538. CtFree(ct, c);
  3539. }
  3540. if (ret != ERR_NO_ERROR)
  3541. {
  3542. // Error has occurred
  3543. CmdPrintError(c, ret);
  3544. }
  3545. CiFreeClientGetAccount(&t);
  3546. // Release of the parameter list
  3547. FreeParamValueList(o);
  3548. return ret;
  3549. }
  3550. // Delete the connection settings
  3551. UINT PcAccountDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3552. {
  3553. LIST *o;
  3554. PC *pc = (PC *)param;
  3555. UINT ret = ERR_NO_ERROR;
  3556. RPC_CLIENT_DELETE_ACCOUNT t;
  3557. // Parameter list that can be specified
  3558. PARAM args[] =
  3559. {
  3560. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  3561. };
  3562. // Get the parameter list
  3563. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3564. if (o == NULL)
  3565. {
  3566. return ERR_INVALID_PARAMETER;
  3567. }
  3568. // RPC call
  3569. Zero(&t, sizeof(t));
  3570. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  3571. ret = CcDeleteAccount(pc->RemoteClient, &t);
  3572. if (ret == ERR_NO_ERROR)
  3573. {
  3574. // Success
  3575. }
  3576. if (ret != ERR_NO_ERROR)
  3577. {
  3578. // Error has occurred
  3579. CmdPrintError(c, ret);
  3580. }
  3581. // Release of the parameter list
  3582. FreeParamValueList(o);
  3583. return ret;
  3584. }
  3585. // Set the user name used to connect with connection settings
  3586. UINT PcAccountUsernameSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3587. {
  3588. LIST *o;
  3589. PC *pc = (PC *)param;
  3590. UINT ret = ERR_NO_ERROR;
  3591. RPC_CLIENT_GET_ACCOUNT t;
  3592. // Parameter list that can be specified
  3593. PARAM args[] =
  3594. {
  3595. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  3596. {"USERNAME", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Username"), CmdEvalNotEmpty, NULL},
  3597. };
  3598. // Get the parameter list
  3599. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3600. if (o == NULL)
  3601. {
  3602. return ERR_INVALID_PARAMETER;
  3603. }
  3604. // RPC call
  3605. Zero(&t, sizeof(t));
  3606. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  3607. ret = CcGetAccount(pc->RemoteClient, &t);
  3608. if (ret == ERR_NO_ERROR)
  3609. {
  3610. RPC_CLIENT_CREATE_ACCOUNT z;
  3611. // Change the settings
  3612. StrCpy(t.ClientAuth->Username, sizeof(t.ClientAuth->Username), GetParamStr(o, "USERNAME"));
  3613. if (t.ClientAuth->AuthType == CLIENT_AUTHTYPE_PASSWORD)
  3614. {
  3615. c->Write(c, _UU("CMD_AccountUsername_Notice"));
  3616. }
  3617. Zero(&z, sizeof(z));
  3618. z.CheckServerCert = t.CheckServerCert;
  3619. z.ClientAuth = t.ClientAuth;
  3620. z.ClientOption = t.ClientOption;
  3621. z.ServerCert = t.ServerCert;
  3622. z.StartupAccount = t.StartupAccount;
  3623. ret = CcSetAccount(pc->RemoteClient, &z);
  3624. }
  3625. if (ret != ERR_NO_ERROR)
  3626. {
  3627. // Error has occurred
  3628. CmdPrintError(c, ret);
  3629. }
  3630. CiFreeClientGetAccount(&t);
  3631. // Release of the parameter list
  3632. FreeParamValueList(o);
  3633. return ret;
  3634. }
  3635. // Set the type of user authentication of connection settings to anonymous authentication
  3636. UINT PcAccountAnonymousSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3637. {
  3638. LIST *o;
  3639. PC *pc = (PC *)param;
  3640. UINT ret = ERR_NO_ERROR;
  3641. RPC_CLIENT_GET_ACCOUNT t;
  3642. // Parameter list that can be specified
  3643. PARAM args[] =
  3644. {
  3645. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  3646. };
  3647. // Get the parameter list
  3648. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3649. if (o == NULL)
  3650. {
  3651. return ERR_INVALID_PARAMETER;
  3652. }
  3653. // RPC call
  3654. Zero(&t, sizeof(t));
  3655. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  3656. ret = CcGetAccount(pc->RemoteClient, &t);
  3657. if (ret == ERR_NO_ERROR)
  3658. {
  3659. RPC_CLIENT_CREATE_ACCOUNT z;
  3660. // Change the settings
  3661. t.ClientAuth->AuthType = CLIENT_AUTHTYPE_ANONYMOUS;
  3662. Zero(&z, sizeof(z));
  3663. z.CheckServerCert = t.CheckServerCert;
  3664. z.ClientAuth = t.ClientAuth;
  3665. z.ClientOption = t.ClientOption;
  3666. z.ServerCert = t.ServerCert;
  3667. z.StartupAccount = t.StartupAccount;
  3668. ret = CcSetAccount(pc->RemoteClient, &z);
  3669. }
  3670. if (ret != ERR_NO_ERROR)
  3671. {
  3672. // Error has occurred
  3673. CmdPrintError(c, ret);
  3674. }
  3675. CiFreeClientGetAccount(&t);
  3676. // Release of the parameter list
  3677. FreeParamValueList(o);
  3678. return ret;
  3679. }
  3680. // Set the type of user authentication of connection settings to the password authentication
  3681. UINT PcAccountPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3682. {
  3683. LIST *o;
  3684. PC *pc = (PC *)param;
  3685. UINT ret = ERR_NO_ERROR;
  3686. RPC_CLIENT_GET_ACCOUNT t;
  3687. // Parameter list that can be specified
  3688. PARAM args[] =
  3689. {
  3690. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  3691. {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},
  3692. {"TYPE", CmdPrompt, _UU("CMD_CascadePasswordSet_Prompt_Type"), CmdEvalNotEmpty, NULL},
  3693. };
  3694. // Get the parameter list
  3695. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3696. if (o == NULL)
  3697. {
  3698. return ERR_INVALID_PARAMETER;
  3699. }
  3700. // RPC call
  3701. Zero(&t, sizeof(t));
  3702. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  3703. ret = CcGetAccount(pc->RemoteClient, &t);
  3704. if (ret == ERR_NO_ERROR)
  3705. {
  3706. char *typestr = GetParamStr(o, "TYPE");
  3707. RPC_CLIENT_CREATE_ACCOUNT z;
  3708. // Change the settings
  3709. if (StartWith("standard", typestr))
  3710. {
  3711. t.ClientAuth->AuthType = CLIENT_AUTHTYPE_PASSWORD;
  3712. HashPassword(t.ClientAuth->HashedPassword, t.ClientAuth->Username,
  3713. GetParamStr(o, "PASSWORD"));
  3714. }
  3715. else if (StartWith("radius", typestr) || StartWith("ntdomain", typestr))
  3716. {
  3717. t.ClientAuth->AuthType = CLIENT_AUTHTYPE_PLAIN_PASSWORD;
  3718. StrCpy(t.ClientAuth->PlainPassword, sizeof(t.ClientAuth->PlainPassword),
  3719. GetParamStr(o, "PASSWORD"));
  3720. }
  3721. else
  3722. {
  3723. // Error has occured
  3724. c->Write(c, _UU("CMD_CascadePasswordSet_Type_Invalid"));
  3725. ret = ERR_INVALID_PARAMETER;
  3726. }
  3727. if (ret == ERR_NO_ERROR)
  3728. {
  3729. Zero(&z, sizeof(z));
  3730. z.CheckServerCert = t.CheckServerCert;
  3731. z.ClientAuth = t.ClientAuth;
  3732. z.ClientOption = t.ClientOption;
  3733. z.ServerCert = t.ServerCert;
  3734. z.StartupAccount = t.StartupAccount;
  3735. ret = CcSetAccount(pc->RemoteClient, &z);
  3736. }
  3737. }
  3738. if (ret != ERR_NO_ERROR)
  3739. {
  3740. // Error has occurred
  3741. CmdPrintError(c, ret);
  3742. }
  3743. CiFreeClientGetAccount(&t);
  3744. // Release of the parameter list
  3745. FreeParamValueList(o);
  3746. return ret;
  3747. }
  3748. // Set the type of user authentication of connection settings to the client certificate authentication
  3749. UINT PcAccountCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3750. {
  3751. LIST *o;
  3752. PC *pc = (PC *)param;
  3753. UINT ret = ERR_NO_ERROR;
  3754. RPC_CLIENT_GET_ACCOUNT t;
  3755. X *x;
  3756. K *k;
  3757. // Parameter list that can be specified
  3758. PARAM args[] =
  3759. {
  3760. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  3761. {"LOADCERT", CmdPrompt, _UU("CMD_LOADCERTPATH"), CmdEvalIsFile, NULL},
  3762. {"LOADKEY", CmdPrompt, _UU("CMD_LOADKEYPATH"), CmdEvalIsFile, NULL},
  3763. };
  3764. // Get the parameter list
  3765. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3766. if (o == NULL)
  3767. {
  3768. return ERR_INVALID_PARAMETER;
  3769. }
  3770. if (CmdLoadCertAndKey(c, &x, &k, GetParamUniStr(o, "LOADCERT"), GetParamUniStr(o, "LOADKEY")) == false)
  3771. {
  3772. return ERR_INTERNAL_ERROR;
  3773. }
  3774. // RPC call
  3775. Zero(&t, sizeof(t));
  3776. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  3777. ret = CcGetAccount(pc->RemoteClient, &t);
  3778. if (ret == ERR_NO_ERROR)
  3779. {
  3780. RPC_CLIENT_CREATE_ACCOUNT z;
  3781. t.ClientAuth->AuthType = CLIENT_AUTHTYPE_CERT;
  3782. if (t.ClientAuth->ClientX != NULL)
  3783. {
  3784. FreeX(t.ClientAuth->ClientX);
  3785. }
  3786. if (t.ClientAuth->ClientK != NULL)
  3787. {
  3788. FreeK(t.ClientAuth->ClientK);
  3789. }
  3790. t.ClientAuth->ClientX = CloneX(x);
  3791. t.ClientAuth->ClientK = CloneK(k);
  3792. Zero(&z, sizeof(z));
  3793. z.CheckServerCert = t.CheckServerCert;
  3794. z.ClientAuth = t.ClientAuth;
  3795. z.ClientOption = t.ClientOption;
  3796. z.ServerCert = t.ServerCert;
  3797. z.StartupAccount = t.StartupAccount;
  3798. ret = CcSetAccount(pc->RemoteClient, &z);
  3799. }
  3800. if (ret != ERR_NO_ERROR)
  3801. {
  3802. // Error has occurred
  3803. CmdPrintError(c, ret);
  3804. }
  3805. FreeX(x);
  3806. FreeK(k);
  3807. CiFreeClientGetAccount(&t);
  3808. // Release of the parameter list
  3809. FreeParamValueList(o);
  3810. return ret;
  3811. }
  3812. // Get the client certificate to be used for the connection settings
  3813. UINT PcAccountCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3814. {
  3815. LIST *o;
  3816. PC *pc = (PC *)param;
  3817. UINT ret = ERR_NO_ERROR;
  3818. RPC_CLIENT_GET_ACCOUNT t;
  3819. // Parameter list that can be specified
  3820. PARAM args[] =
  3821. {
  3822. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  3823. {"SAVECERT", CmdPrompt, _UU("CMD_SAVECERTPATH"), CmdEvalNotEmpty, NULL},
  3824. };
  3825. // Get the parameter list
  3826. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3827. if (o == NULL)
  3828. {
  3829. return ERR_INVALID_PARAMETER;
  3830. }
  3831. // RPC call
  3832. Zero(&t, sizeof(t));
  3833. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  3834. ret = CcGetAccount(pc->RemoteClient, &t);
  3835. if (ret == ERR_NO_ERROR)
  3836. {
  3837. if (t.ClientAuth->AuthType != CLIENT_AUTHTYPE_CERT)
  3838. {
  3839. c->Write(c, _UU("CMD_CascadeCertSet_Not_Auth_Cert"));
  3840. ret = ERR_INTERNAL_ERROR;
  3841. }
  3842. else if (t.ClientAuth->ClientX == NULL)
  3843. {
  3844. c->Write(c, _UU("CMD_CascadeCertSet_Cert_Not_Exists"));
  3845. ret = ERR_INTERNAL_ERROR;
  3846. }
  3847. else
  3848. {
  3849. XToFileW(t.ClientAuth->ClientX, GetParamUniStr(o, "SAVECERT"), true);
  3850. }
  3851. }
  3852. CiFreeClientGetAccount(&t);
  3853. if (ret != ERR_NO_ERROR)
  3854. {
  3855. // Error has occurred
  3856. CmdPrintError(c, ret);
  3857. }
  3858. // Release of the parameter list
  3859. FreeParamValueList(o);
  3860. return ret;
  3861. }
  3862. // Disable communication encryption with the connection settings
  3863. UINT PcAccountEncryptDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3864. {
  3865. LIST *o;
  3866. PC *pc = (PC *)param;
  3867. UINT ret = ERR_NO_ERROR;
  3868. RPC_CLIENT_GET_ACCOUNT t;
  3869. // Parameter list that can be specified
  3870. PARAM args[] =
  3871. {
  3872. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  3873. };
  3874. // Get the parameter list
  3875. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3876. if (o == NULL)
  3877. {
  3878. return ERR_INVALID_PARAMETER;
  3879. }
  3880. // RPC call
  3881. Zero(&t, sizeof(t));
  3882. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  3883. ret = CcGetAccount(pc->RemoteClient, &t);
  3884. if (ret == ERR_NO_ERROR)
  3885. {
  3886. RPC_CLIENT_CREATE_ACCOUNT z;
  3887. // Change the settings
  3888. t.ClientOption->UseEncrypt = false;
  3889. Zero(&z, sizeof(z));
  3890. z.CheckServerCert = t.CheckServerCert;
  3891. z.ClientAuth = t.ClientAuth;
  3892. z.ClientOption = t.ClientOption;
  3893. z.ServerCert = t.ServerCert;
  3894. z.StartupAccount = t.StartupAccount;
  3895. ret = CcSetAccount(pc->RemoteClient, &z);
  3896. }
  3897. if (ret != ERR_NO_ERROR)
  3898. {
  3899. // Error has occurred
  3900. CmdPrintError(c, ret);
  3901. }
  3902. CiFreeClientGetAccount(&t);
  3903. // Release of the parameter list
  3904. FreeParamValueList(o);
  3905. return ret;
  3906. }
  3907. // Enable communication encryption with the connection settings
  3908. UINT PcAccountEncryptEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3909. {
  3910. LIST *o;
  3911. PC *pc = (PC *)param;
  3912. UINT ret = ERR_NO_ERROR;
  3913. RPC_CLIENT_GET_ACCOUNT t;
  3914. // Parameter list that can be specified
  3915. PARAM args[] =
  3916. {
  3917. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  3918. };
  3919. // Get the parameter list
  3920. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3921. if (o == NULL)
  3922. {
  3923. return ERR_INVALID_PARAMETER;
  3924. }
  3925. // RPC call
  3926. Zero(&t, sizeof(t));
  3927. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  3928. ret = CcGetAccount(pc->RemoteClient, &t);
  3929. if (ret == ERR_NO_ERROR)
  3930. {
  3931. RPC_CLIENT_CREATE_ACCOUNT z;
  3932. // Change the settings
  3933. t.ClientOption->UseEncrypt = true;
  3934. Zero(&z, sizeof(z));
  3935. z.CheckServerCert = t.CheckServerCert;
  3936. z.ClientAuth = t.ClientAuth;
  3937. z.ClientOption = t.ClientOption;
  3938. z.ServerCert = t.ServerCert;
  3939. z.StartupAccount = t.StartupAccount;
  3940. ret = CcSetAccount(pc->RemoteClient, &z);
  3941. }
  3942. if (ret != ERR_NO_ERROR)
  3943. {
  3944. // Error has occurred
  3945. CmdPrintError(c, ret);
  3946. }
  3947. CiFreeClientGetAccount(&t);
  3948. // Release of the parameter list
  3949. FreeParamValueList(o);
  3950. return ret;
  3951. }
  3952. // Enable communication data compression with the connection settings
  3953. UINT PcAccountCompressEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3954. {
  3955. LIST *o;
  3956. PC *pc = (PC *)param;
  3957. UINT ret = ERR_NO_ERROR;
  3958. RPC_CLIENT_GET_ACCOUNT t;
  3959. // Parameter list that can be specified
  3960. PARAM args[] =
  3961. {
  3962. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  3963. };
  3964. // Get the parameter list
  3965. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  3966. if (o == NULL)
  3967. {
  3968. return ERR_INVALID_PARAMETER;
  3969. }
  3970. // RPC call
  3971. Zero(&t, sizeof(t));
  3972. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  3973. ret = CcGetAccount(pc->RemoteClient, &t);
  3974. if (ret == ERR_NO_ERROR)
  3975. {
  3976. RPC_CLIENT_CREATE_ACCOUNT z;
  3977. // Change the settings
  3978. t.ClientOption->UseCompress = true;
  3979. Zero(&z, sizeof(z));
  3980. z.CheckServerCert = t.CheckServerCert;
  3981. z.ClientAuth = t.ClientAuth;
  3982. z.ClientOption = t.ClientOption;
  3983. z.ServerCert = t.ServerCert;
  3984. z.StartupAccount = t.StartupAccount;
  3985. ret = CcSetAccount(pc->RemoteClient, &z);
  3986. }
  3987. if (ret != ERR_NO_ERROR)
  3988. {
  3989. // Error has occurred
  3990. CmdPrintError(c, ret);
  3991. }
  3992. CiFreeClientGetAccount(&t);
  3993. // Release of the parameter list
  3994. FreeParamValueList(o);
  3995. return ret;
  3996. }
  3997. // Disable communication data compression with the connection settings
  3998. UINT PcAccountCompressDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  3999. {
  4000. LIST *o;
  4001. PC *pc = (PC *)param;
  4002. UINT ret = ERR_NO_ERROR;
  4003. RPC_CLIENT_GET_ACCOUNT t;
  4004. // Parameter list that can be specified
  4005. PARAM args[] =
  4006. {
  4007. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4008. };
  4009. // Get the parameter list
  4010. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4011. if (o == NULL)
  4012. {
  4013. return ERR_INVALID_PARAMETER;
  4014. }
  4015. // RPC call
  4016. Zero(&t, sizeof(t));
  4017. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4018. ret = CcGetAccount(pc->RemoteClient, &t);
  4019. if (ret == ERR_NO_ERROR)
  4020. {
  4021. RPC_CLIENT_CREATE_ACCOUNT z;
  4022. // Change the settings
  4023. t.ClientOption->UseCompress = false;
  4024. Zero(&z, sizeof(z));
  4025. z.CheckServerCert = t.CheckServerCert;
  4026. z.ClientAuth = t.ClientAuth;
  4027. z.ClientOption = t.ClientOption;
  4028. z.ServerCert = t.ServerCert;
  4029. z.StartupAccount = t.StartupAccount;
  4030. ret = CcSetAccount(pc->RemoteClient, &z);
  4031. }
  4032. if (ret != ERR_NO_ERROR)
  4033. {
  4034. // Error has occurred
  4035. CmdPrintError(c, ret);
  4036. }
  4037. CiFreeClientGetAccount(&t);
  4038. // Release of the parameter list
  4039. FreeParamValueList(o);
  4040. return ret;
  4041. }
  4042. // Set the connection method of the connection settings to the direct TCP/IP connection
  4043. UINT PcAccountProxyNone(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4044. {
  4045. LIST *o;
  4046. PC *pc = (PC *)param;
  4047. UINT ret = ERR_NO_ERROR;
  4048. RPC_CLIENT_GET_ACCOUNT t;
  4049. // Parameter list that can be specified
  4050. PARAM args[] =
  4051. {
  4052. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4053. };
  4054. // Get the parameter list
  4055. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4056. if (o == NULL)
  4057. {
  4058. return ERR_INVALID_PARAMETER;
  4059. }
  4060. // RPC call
  4061. Zero(&t, sizeof(t));
  4062. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4063. ret = CcGetAccount(pc->RemoteClient, &t);
  4064. if (ret == ERR_NO_ERROR)
  4065. {
  4066. RPC_CLIENT_CREATE_ACCOUNT z;
  4067. // Change the settings
  4068. t.ClientOption->ProxyType = PROXY_DIRECT;
  4069. Zero(&z, sizeof(z));
  4070. z.CheckServerCert = t.CheckServerCert;
  4071. z.ClientAuth = t.ClientAuth;
  4072. z.ClientOption = t.ClientOption;
  4073. z.ServerCert = t.ServerCert;
  4074. z.StartupAccount = t.StartupAccount;
  4075. ret = CcSetAccount(pc->RemoteClient, &z);
  4076. }
  4077. if (ret != ERR_NO_ERROR)
  4078. {
  4079. // Error has occurred
  4080. CmdPrintError(c, ret);
  4081. }
  4082. CiFreeClientGetAccount(&t);
  4083. // Release of the parameter list
  4084. FreeParamValueList(o);
  4085. return ret;
  4086. }
  4087. // Set the connection method of the connection settings to the HTTP proxy server connection
  4088. UINT PcAccountProxyHttp(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4089. {
  4090. LIST *o;
  4091. PC *pc = (PC *)param;
  4092. UINT ret = ERR_NO_ERROR;
  4093. RPC_CLIENT_GET_ACCOUNT t;
  4094. // Parameter list that can be specified
  4095. PARAM args[] =
  4096. {
  4097. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4098. {"SERVER", CmdPrompt, _UU("CMD_AccountProxyHttp_Prompt_Server"), CmdEvalHostAndPort, NULL},
  4099. {"USERNAME", NULL, NULL, NULL, NULL},
  4100. {"PASSWORD", NULL, NULL, NULL, NULL},
  4101. };
  4102. // Get the parameter list
  4103. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4104. if (o == NULL)
  4105. {
  4106. return ERR_INVALID_PARAMETER;
  4107. }
  4108. // RPC call
  4109. Zero(&t, sizeof(t));
  4110. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4111. ret = CcGetAccount(pc->RemoteClient, &t);
  4112. if (ret == ERR_NO_ERROR)
  4113. {
  4114. RPC_CLIENT_CREATE_ACCOUNT z;
  4115. char *host;
  4116. UINT port;
  4117. // Data change
  4118. if (ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 8080))
  4119. {
  4120. t.ClientOption->ProxyType = PROXY_HTTP;
  4121. StrCpy(t.ClientOption->ProxyName, sizeof(t.ClientOption->ProxyName), host);
  4122. t.ClientOption->ProxyPort = port;
  4123. StrCpy(t.ClientOption->ProxyUsername, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "USERNAME"));
  4124. StrCpy(t.ClientOption->ProxyPassword, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "PASSWORD"));
  4125. Free(host);
  4126. }
  4127. Zero(&z, sizeof(z));
  4128. z.CheckServerCert = t.CheckServerCert;
  4129. z.ClientAuth = t.ClientAuth;
  4130. z.ClientOption = t.ClientOption;
  4131. z.ServerCert = t.ServerCert;
  4132. z.StartupAccount = t.StartupAccount;
  4133. ret = CcSetAccount(pc->RemoteClient, &z);
  4134. }
  4135. if (ret != ERR_NO_ERROR)
  4136. {
  4137. // Error has occurred
  4138. CmdPrintError(c, ret);
  4139. }
  4140. CiFreeClientGetAccount(&t);
  4141. // Release of the parameter list
  4142. FreeParamValueList(o);
  4143. return ret;
  4144. }
  4145. // Set the connection method of the connection settings to the SOCKS proxy server connection
  4146. UINT PcAccountProxySocks(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4147. {
  4148. LIST *o;
  4149. PC *pc = (PC *)param;
  4150. UINT ret = ERR_NO_ERROR;
  4151. RPC_CLIENT_GET_ACCOUNT t;
  4152. // Parameter list that can be specified
  4153. PARAM args[] =
  4154. {
  4155. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4156. {"SERVER", CmdPrompt, _UU("CMD_AccountProxyHttp_Prompt_Server"), CmdEvalHostAndPort, NULL},
  4157. {"USERNAME", NULL, NULL, NULL, NULL},
  4158. {"PASSWORD", NULL, NULL, NULL, NULL},
  4159. };
  4160. // Get the parameter list
  4161. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4162. if (o == NULL)
  4163. {
  4164. return ERR_INVALID_PARAMETER;
  4165. }
  4166. // RPC call
  4167. Zero(&t, sizeof(t));
  4168. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4169. ret = CcGetAccount(pc->RemoteClient, &t);
  4170. if (ret == ERR_NO_ERROR)
  4171. {
  4172. RPC_CLIENT_CREATE_ACCOUNT z;
  4173. char *host;
  4174. UINT port;
  4175. // Data change
  4176. if (ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 8080))
  4177. {
  4178. t.ClientOption->ProxyType = PROXY_SOCKS;
  4179. StrCpy(t.ClientOption->ProxyName, sizeof(t.ClientOption->ProxyName), host);
  4180. t.ClientOption->ProxyPort = port;
  4181. StrCpy(t.ClientOption->ProxyUsername, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "USERNAME"));
  4182. StrCpy(t.ClientOption->ProxyPassword, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "PASSWORD"));
  4183. Free(host);
  4184. }
  4185. Zero(&z, sizeof(z));
  4186. z.CheckServerCert = t.CheckServerCert;
  4187. z.ClientAuth = t.ClientAuth;
  4188. z.ClientOption = t.ClientOption;
  4189. z.ServerCert = t.ServerCert;
  4190. z.StartupAccount = t.StartupAccount;
  4191. ret = CcSetAccount(pc->RemoteClient, &z);
  4192. }
  4193. if (ret != ERR_NO_ERROR)
  4194. {
  4195. // Error has occurred
  4196. CmdPrintError(c, ret);
  4197. }
  4198. CiFreeClientGetAccount(&t);
  4199. // Release of the parameter list
  4200. FreeParamValueList(o);
  4201. return ret;
  4202. }
  4203. // Enable validation option for server certificate of connection settings
  4204. UINT PcAccountServerCertEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4205. {
  4206. LIST *o;
  4207. PC *pc = (PC *)param;
  4208. UINT ret = ERR_NO_ERROR;
  4209. RPC_CLIENT_GET_ACCOUNT t;
  4210. // Parameter list that can be specified
  4211. PARAM args[] =
  4212. {
  4213. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4214. };
  4215. // Get the parameter list
  4216. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4217. if (o == NULL)
  4218. {
  4219. return ERR_INVALID_PARAMETER;
  4220. }
  4221. // RPC call
  4222. Zero(&t, sizeof(t));
  4223. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4224. ret = CcGetAccount(pc->RemoteClient, &t);
  4225. if (ret == ERR_NO_ERROR)
  4226. {
  4227. RPC_CLIENT_CREATE_ACCOUNT z;
  4228. // Change the settings
  4229. t.CheckServerCert = true;
  4230. Zero(&z, sizeof(z));
  4231. z.CheckServerCert = t.CheckServerCert;
  4232. z.ClientAuth = t.ClientAuth;
  4233. z.ClientOption = t.ClientOption;
  4234. z.ServerCert = t.ServerCert;
  4235. z.StartupAccount = t.StartupAccount;
  4236. ret = CcSetAccount(pc->RemoteClient, &z);
  4237. }
  4238. if (ret != ERR_NO_ERROR)
  4239. {
  4240. // Error has occurred
  4241. CmdPrintError(c, ret);
  4242. }
  4243. CiFreeClientGetAccount(&t);
  4244. // Release of the parameter list
  4245. FreeParamValueList(o);
  4246. return ret;
  4247. }
  4248. // Disable validation option of the server certificate of connection settings
  4249. UINT PcAccountServerCertDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4250. {
  4251. LIST *o;
  4252. PC *pc = (PC *)param;
  4253. UINT ret = ERR_NO_ERROR;
  4254. RPC_CLIENT_GET_ACCOUNT t;
  4255. // Parameter list that can be specified
  4256. PARAM args[] =
  4257. {
  4258. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4259. };
  4260. // Get the parameter list
  4261. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4262. if (o == NULL)
  4263. {
  4264. return ERR_INVALID_PARAMETER;
  4265. }
  4266. // RPC call
  4267. Zero(&t, sizeof(t));
  4268. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4269. ret = CcGetAccount(pc->RemoteClient, &t);
  4270. if (ret == ERR_NO_ERROR)
  4271. {
  4272. RPC_CLIENT_CREATE_ACCOUNT z;
  4273. // Change the settings
  4274. t.CheckServerCert = false;
  4275. Zero(&z, sizeof(z));
  4276. z.CheckServerCert = t.CheckServerCert;
  4277. z.ClientAuth = t.ClientAuth;
  4278. z.ClientOption = t.ClientOption;
  4279. z.ServerCert = t.ServerCert;
  4280. z.StartupAccount = t.StartupAccount;
  4281. ret = CcSetAccount(pc->RemoteClient, &z);
  4282. }
  4283. if (ret != ERR_NO_ERROR)
  4284. {
  4285. // Error has occurred
  4286. CmdPrintError(c, ret);
  4287. }
  4288. CiFreeClientGetAccount(&t);
  4289. // Release of the parameter list
  4290. FreeParamValueList(o);
  4291. return ret;
  4292. }
  4293. // Set the server-specific certificate of connection settings
  4294. UINT PcAccountServerCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4295. {
  4296. LIST *o;
  4297. PC *pc = (PC *)param;
  4298. UINT ret = ERR_NO_ERROR;
  4299. RPC_CLIENT_GET_ACCOUNT t;
  4300. X *x;
  4301. // Parameter list that can be specified
  4302. PARAM args[] =
  4303. {
  4304. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4305. {"LOADCERT", CmdPrompt, _UU("CMD_LOADCERTPATH"), CmdEvalIsFile, NULL},
  4306. };
  4307. // Get the parameter list
  4308. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4309. if (o == NULL)
  4310. {
  4311. return ERR_INVALID_PARAMETER;
  4312. }
  4313. x = FileToXW(GetParamUniStr(o, "LOADCERT"));
  4314. if (x == NULL)
  4315. {
  4316. FreeParamValueList(o);
  4317. c->Write(c, _UU("CMD_LOADCERT_FAILED"));
  4318. return ERR_INTERNAL_ERROR;
  4319. }
  4320. // RPC call
  4321. Zero(&t, sizeof(t));
  4322. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4323. ret = CcGetAccount(pc->RemoteClient, &t);
  4324. if (ret == ERR_NO_ERROR)
  4325. {
  4326. RPC_CLIENT_CREATE_ACCOUNT z;
  4327. // Change the settings
  4328. if (t.ServerCert != NULL)
  4329. {
  4330. FreeX(t.ServerCert);
  4331. }
  4332. t.ServerCert = CloneX(x);
  4333. Zero(&z, sizeof(z));
  4334. z.CheckServerCert = t.CheckServerCert;
  4335. z.ClientAuth = t.ClientAuth;
  4336. z.ClientOption = t.ClientOption;
  4337. z.ServerCert = t.ServerCert;
  4338. z.StartupAccount = t.StartupAccount;
  4339. ret = CcSetAccount(pc->RemoteClient, &z);
  4340. }
  4341. if (ret != ERR_NO_ERROR)
  4342. {
  4343. // Error has occurred
  4344. CmdPrintError(c, ret);
  4345. }
  4346. CiFreeClientGetAccount(&t);
  4347. // Release of the parameter list
  4348. FreeParamValueList(o);
  4349. FreeX(x);
  4350. return ret;
  4351. }
  4352. // Delete a server-specific certificate of connection settings
  4353. UINT PcAccountServerCertDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4354. {
  4355. LIST *o;
  4356. PC *pc = (PC *)param;
  4357. UINT ret = ERR_NO_ERROR;
  4358. RPC_CLIENT_GET_ACCOUNT t;
  4359. // Parameter list that can be specified
  4360. PARAM args[] =
  4361. {
  4362. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4363. };
  4364. // Get the parameter list
  4365. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4366. if (o == NULL)
  4367. {
  4368. return ERR_INVALID_PARAMETER;
  4369. }
  4370. // RPC call
  4371. Zero(&t, sizeof(t));
  4372. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4373. ret = CcGetAccount(pc->RemoteClient, &t);
  4374. if (ret == ERR_NO_ERROR)
  4375. {
  4376. RPC_CLIENT_CREATE_ACCOUNT z;
  4377. // Change the settings
  4378. if (t.ServerCert != NULL)
  4379. {
  4380. FreeX(t.ServerCert);
  4381. }
  4382. t.ServerCert = NULL;
  4383. Zero(&z, sizeof(z));
  4384. z.CheckServerCert = t.CheckServerCert;
  4385. z.ClientAuth = t.ClientAuth;
  4386. z.ClientOption = t.ClientOption;
  4387. z.ServerCert = t.ServerCert;
  4388. z.StartupAccount = t.StartupAccount;
  4389. ret = CcSetAccount(pc->RemoteClient, &z);
  4390. }
  4391. if (ret != ERR_NO_ERROR)
  4392. {
  4393. // Error has occurred
  4394. CmdPrintError(c, ret);
  4395. }
  4396. CiFreeClientGetAccount(&t);
  4397. // Release of the parameter list
  4398. FreeParamValueList(o);
  4399. return ret;
  4400. }
  4401. // Get a server-specific certificate of connection settings
  4402. UINT PcAccountServerCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4403. {
  4404. LIST *o;
  4405. PC *pc = (PC *)param;
  4406. UINT ret = ERR_NO_ERROR;
  4407. RPC_CLIENT_GET_ACCOUNT t;
  4408. // Parameter list that can be specified
  4409. PARAM args[] =
  4410. {
  4411. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4412. {"SAVECERT", CmdPrompt, _UU("CMD_SAVECERTPATH"), CmdEvalNotEmpty, NULL},
  4413. };
  4414. // Get the parameter list
  4415. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4416. if (o == NULL)
  4417. {
  4418. return ERR_INVALID_PARAMETER;
  4419. }
  4420. // RPC call
  4421. Zero(&t, sizeof(t));
  4422. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4423. ret = CcGetAccount(pc->RemoteClient, &t);
  4424. if (ret == ERR_NO_ERROR)
  4425. {
  4426. RPC_CLIENT_CREATE_ACCOUNT z;
  4427. // Change the settings
  4428. if (t.ServerCert != NULL)
  4429. {
  4430. FreeX(t.ServerCert);
  4431. }
  4432. t.ServerCert = NULL;
  4433. Zero(&z, sizeof(z));
  4434. z.CheckServerCert = t.CheckServerCert;
  4435. z.ClientAuth = t.ClientAuth;
  4436. z.ClientOption = t.ClientOption;
  4437. z.ServerCert = t.ServerCert;
  4438. z.StartupAccount = t.StartupAccount;
  4439. ret = CcSetAccount(pc->RemoteClient, &z);
  4440. }
  4441. if (ret != ERR_NO_ERROR)
  4442. {
  4443. // Error has occurred
  4444. CmdPrintError(c, ret);
  4445. }
  4446. CiFreeClientGetAccount(&t);
  4447. // Release of the parameter list
  4448. FreeParamValueList(o);
  4449. return ret;
  4450. }
  4451. // Set the advanced settings of connection settings
  4452. UINT PcAccountDetailSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4453. {
  4454. LIST *o;
  4455. PC *pc = (PC *)param;
  4456. UINT ret = ERR_NO_ERROR;
  4457. RPC_CLIENT_GET_ACCOUNT t;
  4458. CMD_EVAL_MIN_MAX mm_maxtcp =
  4459. {
  4460. "CMD_CascadeDetailSet_Eval_MaxTcp", 1, 32
  4461. };
  4462. CMD_EVAL_MIN_MAX mm_interval =
  4463. {
  4464. "CMD_CascadeDetailSet_Eval_Interval", 1, 4294967295UL
  4465. };
  4466. // Parameter list that can be specified
  4467. PARAM args[] =
  4468. {
  4469. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4470. {"MAXTCP", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_MaxTcp"), CmdEvalMinMax, &mm_maxtcp},
  4471. {"INTERVAL", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_Interval"), CmdEvalMinMax, &mm_interval},
  4472. {"TTL", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_TTL"), NULL, NULL},
  4473. {"HALF", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_HALF"), NULL, NULL},
  4474. {"BRIDGE", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_BRIDGE"), NULL, NULL},
  4475. {"MONITOR", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_MONITOR"), NULL, NULL},
  4476. {"NOTRACK", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_NOTRACK"), NULL, NULL},
  4477. {"NOQOS", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_NOQOS"), NULL, NULL},
  4478. };
  4479. // Get the parameter list
  4480. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4481. if (o == NULL)
  4482. {
  4483. return ERR_INVALID_PARAMETER;
  4484. }
  4485. // RPC call
  4486. Zero(&t, sizeof(t));
  4487. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4488. ret = CcGetAccount(pc->RemoteClient, &t);
  4489. if (ret == ERR_NO_ERROR)
  4490. {
  4491. RPC_CLIENT_CREATE_ACCOUNT z;
  4492. // Data change
  4493. t.ClientOption->MaxConnection = GetParamInt(o, "MAXTCP");
  4494. t.ClientOption->AdditionalConnectionInterval = GetParamInt(o, "INTERVAL");
  4495. t.ClientOption->ConnectionDisconnectSpan = GetParamInt(o, "TTL");
  4496. t.ClientOption->HalfConnection = GetParamYes(o, "HALF");
  4497. t.ClientOption->RequireBridgeRoutingMode = GetParamYes(o, "BRIDGE");
  4498. t.ClientOption->RequireMonitorMode = GetParamYes(o, "MONITOR");
  4499. t.ClientOption->NoRoutingTracking = GetParamYes(o, "NOTRACK");
  4500. t.ClientOption->DisableQoS = GetParamYes(o, "NOQOS");
  4501. Zero(&z, sizeof(z));
  4502. z.CheckServerCert = t.CheckServerCert;
  4503. z.ClientAuth = t.ClientAuth;
  4504. z.ClientOption = t.ClientOption;
  4505. z.ServerCert = t.ServerCert;
  4506. z.StartupAccount = t.StartupAccount;
  4507. ret = CcSetAccount(pc->RemoteClient, &z);
  4508. }
  4509. if (ret != ERR_NO_ERROR)
  4510. {
  4511. // Error has occurred
  4512. CmdPrintError(c, ret);
  4513. }
  4514. CiFreeClientGetAccount(&t);
  4515. // Release of the parameter list
  4516. FreeParamValueList(o);
  4517. return ret;
  4518. }
  4519. // Change the name of the connection settings
  4520. UINT PcAccountRename(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4521. {
  4522. LIST *o;
  4523. PC *pc = (PC *)param;
  4524. UINT ret = ERR_NO_ERROR;
  4525. RPC_RENAME_ACCOUNT t;
  4526. // Parameter list that can be specified
  4527. PARAM args[] =
  4528. {
  4529. {"[name]", CmdPrompt, _UU("CMD_AccountRename_PROMPT_OLD"), CmdEvalNotEmpty, NULL},
  4530. {"NEW", CmdPrompt, _UU("CMD_AccountRename_PROMPT_NEW"), CmdEvalNotEmpty, NULL},
  4531. };
  4532. // Get the parameter list
  4533. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4534. if (o == NULL)
  4535. {
  4536. return ERR_INVALID_PARAMETER;
  4537. }
  4538. // RPC call
  4539. Zero(&t, sizeof(t));
  4540. UniStrCpy(t.NewName, sizeof(t.NewName), GetParamUniStr(o, "NEW"));
  4541. UniStrCpy(t.OldName, sizeof(t.OldName), GetParamUniStr(o, "[name]"));
  4542. ret = CcRenameAccount(pc->RemoteClient, &t);
  4543. if (ret == ERR_NO_ERROR)
  4544. {
  4545. // Success
  4546. }
  4547. if (ret != ERR_NO_ERROR)
  4548. {
  4549. // Error has occurred
  4550. CmdPrintError(c, ret);
  4551. }
  4552. // Release of the parameter list
  4553. FreeParamValueList(o);
  4554. return ret;
  4555. }
  4556. // Start to connect to the VPN Server using the connection settings
  4557. UINT PcAccountConnect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4558. {
  4559. LIST *o;
  4560. PC *pc = (PC *)param;
  4561. UINT ret = ERR_NO_ERROR;
  4562. RPC_CLIENT_CONNECT t;
  4563. // Parameter list that can be specified
  4564. PARAM args[] =
  4565. {
  4566. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4567. };
  4568. // Get the parameter list
  4569. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4570. if (o == NULL)
  4571. {
  4572. return ERR_INVALID_PARAMETER;
  4573. }
  4574. // RPC call
  4575. Zero(&t, sizeof(t));
  4576. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4577. ret = CcConnect(pc->RemoteClient, &t);
  4578. if (ret == ERR_NO_ERROR)
  4579. {
  4580. // Success
  4581. }
  4582. if (ret != ERR_NO_ERROR)
  4583. {
  4584. // Error has occurred
  4585. CmdPrintError(c, ret);
  4586. }
  4587. // Release of the parameter list
  4588. FreeParamValueList(o);
  4589. return ret;
  4590. }
  4591. // Disconnect the connection settings of connected
  4592. UINT PcAccountDisconnect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4593. {
  4594. LIST *o;
  4595. PC *pc = (PC *)param;
  4596. UINT ret = ERR_NO_ERROR;
  4597. RPC_CLIENT_CONNECT t;
  4598. // Parameter list that can be specified
  4599. PARAM args[] =
  4600. {
  4601. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4602. };
  4603. // Get the parameter list
  4604. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4605. if (o == NULL)
  4606. {
  4607. return ERR_INVALID_PARAMETER;
  4608. }
  4609. // RPC call
  4610. Zero(&t, sizeof(t));
  4611. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4612. ret = CcDisconnect(pc->RemoteClient, &t);
  4613. if (ret == ERR_NO_ERROR)
  4614. {
  4615. // Success
  4616. }
  4617. if (ret != ERR_NO_ERROR)
  4618. {
  4619. // Error has occurred
  4620. CmdPrintError(c, ret);
  4621. }
  4622. // Release of the parameter list
  4623. FreeParamValueList(o);
  4624. return ret;
  4625. }
  4626. // Get the current state of the connection settings
  4627. UINT PcAccountStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4628. {
  4629. LIST *o;
  4630. PC *pc = (PC *)param;
  4631. UINT ret = ERR_NO_ERROR;
  4632. RPC_CLIENT_GET_CONNECTION_STATUS t;
  4633. // Parameter list that can be specified
  4634. PARAM args[] =
  4635. {
  4636. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4637. };
  4638. // Get the parameter list
  4639. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4640. if (o == NULL)
  4641. {
  4642. return ERR_INVALID_PARAMETER;
  4643. }
  4644. // RPC call
  4645. Zero(&t, sizeof(t));
  4646. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4647. ret = CcGetAccountStatus(pc->RemoteClient, &t);
  4648. if (ret == ERR_NO_ERROR)
  4649. {
  4650. if (t.Active == false)
  4651. {
  4652. // Has been disconnected
  4653. ret = ERR_ACCOUNT_INACTIVE;
  4654. }
  4655. else
  4656. {
  4657. CT *ct = CtNewStandard();
  4658. CmdPrintStatusToListView(ct, &t);
  4659. CtFree(ct, c);
  4660. }
  4661. }
  4662. if (ret != ERR_NO_ERROR)
  4663. {
  4664. // Error has occurred
  4665. CmdPrintError(c, ret);
  4666. }
  4667. CiFreeClientGetConnectionStatus(&t);
  4668. // Release of the parameter list
  4669. FreeParamValueList(o);
  4670. return ret;
  4671. }
  4672. // Set a virtual LAN card to be used in the connection settings
  4673. UINT PcAccountNicSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4674. {
  4675. LIST *o;
  4676. PC *pc = (PC *)param;
  4677. UINT ret = ERR_NO_ERROR;
  4678. RPC_CLIENT_GET_ACCOUNT t;
  4679. // Parameter list that can be specified
  4680. PARAM args[] =
  4681. {
  4682. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4683. {"NICNAME", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Nicname"), CmdEvalNotEmpty, NULL},
  4684. };
  4685. // Get the parameter list
  4686. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4687. if (o == NULL)
  4688. {
  4689. return ERR_INVALID_PARAMETER;
  4690. }
  4691. // RPC call
  4692. Zero(&t, sizeof(t));
  4693. Zero(&t, sizeof(t));
  4694. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4695. ret = CcGetAccount(pc->RemoteClient, &t);
  4696. if (ret == ERR_NO_ERROR)
  4697. {
  4698. RPC_CLIENT_CREATE_ACCOUNT c;
  4699. // Success
  4700. StrCpy(t.ClientOption->DeviceName, sizeof(t.ClientOption->DeviceName),
  4701. GetParamStr(o, "NICNAME"));
  4702. Zero(&c, sizeof(c));
  4703. c.ClientAuth = t.ClientAuth;
  4704. c.ClientOption = t.ClientOption;
  4705. c.CheckServerCert = t.CheckServerCert;
  4706. c.ServerCert = t.ServerCert;
  4707. c.StartupAccount = t.StartupAccount;
  4708. ret = CcSetAccount(pc->RemoteClient, &c);
  4709. }
  4710. if (ret != ERR_NO_ERROR)
  4711. {
  4712. // Error has occurred
  4713. CmdPrintError(c, ret);
  4714. }
  4715. CiFreeClientGetAccount(&t);
  4716. // Release of the parameter list
  4717. FreeParamValueList(o);
  4718. return ret;
  4719. }
  4720. // Set to display error screens and connection status while connecting to the VPN Server
  4721. UINT PcAccountStatusShow(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4722. {
  4723. LIST *o;
  4724. PC *pc = (PC *)param;
  4725. UINT ret = ERR_NO_ERROR;
  4726. RPC_CLIENT_GET_ACCOUNT t;
  4727. // Parameter list that can be specified
  4728. PARAM args[] =
  4729. {
  4730. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4731. };
  4732. // Get the parameter list
  4733. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4734. if (o == NULL)
  4735. {
  4736. return ERR_INVALID_PARAMETER;
  4737. }
  4738. // RPC call
  4739. Zero(&t, sizeof(t));
  4740. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4741. ret = CcGetAccount(pc->RemoteClient, &t);
  4742. if (ret == ERR_NO_ERROR)
  4743. {
  4744. RPC_CLIENT_CREATE_ACCOUNT z;
  4745. // Change the settings
  4746. t.ClientOption->HideStatusWindow = false;
  4747. Zero(&z, sizeof(z));
  4748. z.CheckServerCert = t.CheckServerCert;
  4749. z.ClientAuth = t.ClientAuth;
  4750. z.ClientOption = t.ClientOption;
  4751. z.ServerCert = t.ServerCert;
  4752. z.StartupAccount = t.StartupAccount;
  4753. ret = CcSetAccount(pc->RemoteClient, &z);
  4754. }
  4755. if (ret != ERR_NO_ERROR)
  4756. {
  4757. // Error has occurred
  4758. CmdPrintError(c, ret);
  4759. }
  4760. CiFreeClientGetAccount(&t);
  4761. // Release of the parameter list
  4762. FreeParamValueList(o);
  4763. return ret;
  4764. }
  4765. // Configure not to display error screens and connection status while connecting to the VPN Server
  4766. UINT PcAccountStatusHide(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4767. {
  4768. LIST *o;
  4769. PC *pc = (PC *)param;
  4770. UINT ret = ERR_NO_ERROR;
  4771. RPC_CLIENT_GET_ACCOUNT t;
  4772. // Parameter list that can be specified
  4773. PARAM args[] =
  4774. {
  4775. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4776. };
  4777. // Get the parameter list
  4778. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4779. if (o == NULL)
  4780. {
  4781. return ERR_INVALID_PARAMETER;
  4782. }
  4783. // RPC call
  4784. Zero(&t, sizeof(t));
  4785. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4786. ret = CcGetAccount(pc->RemoteClient, &t);
  4787. if (ret == ERR_NO_ERROR)
  4788. {
  4789. RPC_CLIENT_CREATE_ACCOUNT z;
  4790. // Change the settings
  4791. t.ClientOption->HideStatusWindow = true;
  4792. Zero(&z, sizeof(z));
  4793. z.CheckServerCert = t.CheckServerCert;
  4794. z.ClientAuth = t.ClientAuth;
  4795. z.ClientOption = t.ClientOption;
  4796. z.ServerCert = t.ServerCert;
  4797. z.StartupAccount = t.StartupAccount;
  4798. ret = CcSetAccount(pc->RemoteClient, &z);
  4799. }
  4800. if (ret != ERR_NO_ERROR)
  4801. {
  4802. // Error has occurred
  4803. CmdPrintError(c, ret);
  4804. }
  4805. CiFreeClientGetAccount(&t);
  4806. // Release of the parameter list
  4807. FreeParamValueList(o);
  4808. return ret;
  4809. }
  4810. // Set the type of user authentication of connection settings to the smart card authentication
  4811. UINT PcAccountSecureCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4812. {
  4813. LIST *o;
  4814. PC *pc = (PC *)param;
  4815. UINT ret = ERR_NO_ERROR;
  4816. RPC_CLIENT_GET_ACCOUNT t;
  4817. // Parameter list that can be specified
  4818. PARAM args[] =
  4819. {
  4820. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4821. {"CERTNAME", CmdPrompt, _UU("CMD_AccountSecureCertSet_PROMPT_CERTNAME"), CmdEvalNotEmpty, NULL},
  4822. {"KEYNAME", CmdPrompt, _UU("CMD_AccountSecureCertSet_PROMPT_KEYNAME"), CmdEvalNotEmpty, NULL},
  4823. };
  4824. // Get the parameter list
  4825. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4826. if (o == NULL)
  4827. {
  4828. return ERR_INVALID_PARAMETER;
  4829. }
  4830. // RPC call
  4831. Zero(&t, sizeof(t));
  4832. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4833. ret = CcGetAccount(pc->RemoteClient, &t);
  4834. if (ret == ERR_NO_ERROR)
  4835. {
  4836. RPC_CLIENT_CREATE_ACCOUNT z;
  4837. // Change the settings
  4838. t.ClientAuth->AuthType = CLIENT_AUTHTYPE_SECURE;
  4839. StrCpy(t.ClientAuth->SecurePublicCertName, sizeof(t.ClientAuth->SecurePublicCertName),
  4840. GetParamStr(o, "CERTNAME"));
  4841. StrCpy(t.ClientAuth->SecurePrivateKeyName, sizeof(t.ClientAuth->SecurePrivateKeyName),
  4842. GetParamStr(o, "KEYNAME"));
  4843. Zero(&z, sizeof(z));
  4844. z.CheckServerCert = t.CheckServerCert;
  4845. z.ClientAuth = t.ClientAuth;
  4846. z.ClientOption = t.ClientOption;
  4847. z.ServerCert = t.ServerCert;
  4848. z.StartupAccount = t.StartupAccount;
  4849. ret = CcSetAccount(pc->RemoteClient, &z);
  4850. }
  4851. if (ret != ERR_NO_ERROR)
  4852. {
  4853. // Error has occurred
  4854. CmdPrintError(c, ret);
  4855. }
  4856. CiFreeClientGetAccount(&t);
  4857. // Release of the parameter list
  4858. FreeParamValueList(o);
  4859. return ret;
  4860. }
  4861. // Set the retry interval and number of retries when disconnect or connection failure of connection settings
  4862. UINT PcAccountRetrySet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4863. {
  4864. LIST *o;
  4865. PC *pc = (PC *)param;
  4866. UINT ret = ERR_NO_ERROR;
  4867. RPC_CLIENT_GET_ACCOUNT t;
  4868. // Parameter list that can be specified
  4869. CMD_EVAL_MIN_MAX minmax =
  4870. {
  4871. "CMD_AccountRetrySet_EVAL_INTERVAL",
  4872. 5,
  4873. 4294967295UL,
  4874. };
  4875. PARAM args[] =
  4876. {
  4877. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4878. {"NUM", CmdPrompt, _UU("CMD_AccountRetrySet_PROMPT_NUM"), CmdEvalNotEmpty, NULL},
  4879. {"INTERVAL", CmdPrompt, _UU("CMD_AccountRetrySet_PROMPY_INTERVAL"), CmdEvalMinMax, &minmax},
  4880. };
  4881. // Get the parameter list
  4882. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4883. if (o == NULL)
  4884. {
  4885. return ERR_INVALID_PARAMETER;
  4886. }
  4887. // RPC call
  4888. Zero(&t, sizeof(t));
  4889. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4890. ret = CcGetAccount(pc->RemoteClient, &t);
  4891. if (ret == ERR_NO_ERROR)
  4892. {
  4893. RPC_CLIENT_CREATE_ACCOUNT z;
  4894. // Change the settings
  4895. UINT num = GetParamInt(o, "NUM");
  4896. UINT interval = GetParamInt(o, "INTERVAL");
  4897. t.ClientOption->NumRetry = (num == 999) ? INFINITE : num;
  4898. t.ClientOption->RetryInterval = interval;
  4899. Zero(&z, sizeof(z));
  4900. z.CheckServerCert = t.CheckServerCert;
  4901. z.ClientAuth = t.ClientAuth;
  4902. z.ClientOption = t.ClientOption;
  4903. z.ServerCert = t.ServerCert;
  4904. z.StartupAccount = t.StartupAccount;
  4905. ret = CcSetAccount(pc->RemoteClient, &z);
  4906. }
  4907. if (ret != ERR_NO_ERROR)
  4908. {
  4909. // Error has occurred
  4910. CmdPrintError(c, ret);
  4911. }
  4912. CiFreeClientGetAccount(&t);
  4913. // Release of the parameter list
  4914. FreeParamValueList(o);
  4915. return ret;
  4916. }
  4917. // Set to start-up connection the connection settings
  4918. UINT PcAccountStartupSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4919. {
  4920. LIST *o;
  4921. PC *pc = (PC *)param;
  4922. UINT ret = ERR_NO_ERROR;
  4923. RPC_CLIENT_GET_ACCOUNT t;
  4924. // Parameter list that can be specified
  4925. PARAM args[] =
  4926. {
  4927. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4928. };
  4929. // Get the parameter list
  4930. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4931. if (o == NULL)
  4932. {
  4933. return ERR_INVALID_PARAMETER;
  4934. }
  4935. // RPC call
  4936. Zero(&t, sizeof(t));
  4937. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4938. ret = CcGetAccount(pc->RemoteClient, &t);
  4939. if (ret == ERR_NO_ERROR)
  4940. {
  4941. RPC_CLIENT_CREATE_ACCOUNT z;
  4942. // Change the settings
  4943. t.StartupAccount = true;
  4944. Zero(&z, sizeof(z));
  4945. z.CheckServerCert = t.CheckServerCert;
  4946. z.ClientAuth = t.ClientAuth;
  4947. z.ClientOption = t.ClientOption;
  4948. z.ServerCert = t.ServerCert;
  4949. z.StartupAccount = t.StartupAccount;
  4950. ret = CcSetAccount(pc->RemoteClient, &z);
  4951. }
  4952. if (ret != ERR_NO_ERROR)
  4953. {
  4954. // Error has occurred
  4955. CmdPrintError(c, ret);
  4956. }
  4957. CiFreeClientGetAccount(&t);
  4958. // Release of the parameter list
  4959. FreeParamValueList(o);
  4960. return ret;
  4961. }
  4962. // Unset the start-up connection of the connection settings
  4963. UINT PcAccountStartupRemove(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  4964. {
  4965. LIST *o;
  4966. PC *pc = (PC *)param;
  4967. UINT ret = ERR_NO_ERROR;
  4968. RPC_CLIENT_GET_ACCOUNT t;
  4969. // Parameter list that can be specified
  4970. PARAM args[] =
  4971. {
  4972. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  4973. };
  4974. // Get the parameter list
  4975. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  4976. if (o == NULL)
  4977. {
  4978. return ERR_INVALID_PARAMETER;
  4979. }
  4980. // RPC call
  4981. Zero(&t, sizeof(t));
  4982. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  4983. ret = CcGetAccount(pc->RemoteClient, &t);
  4984. if (ret == ERR_NO_ERROR)
  4985. {
  4986. RPC_CLIENT_CREATE_ACCOUNT z;
  4987. // Change the settings
  4988. t.StartupAccount = false;
  4989. Zero(&z, sizeof(z));
  4990. z.CheckServerCert = t.CheckServerCert;
  4991. z.ClientAuth = t.ClientAuth;
  4992. z.ClientOption = t.ClientOption;
  4993. z.ServerCert = t.ServerCert;
  4994. z.StartupAccount = t.StartupAccount;
  4995. ret = CcSetAccount(pc->RemoteClient, &z);
  4996. }
  4997. if (ret != ERR_NO_ERROR)
  4998. {
  4999. // Error has occurred
  5000. CmdPrintError(c, ret);
  5001. }
  5002. CiFreeClientGetAccount(&t);
  5003. // Release of the parameter list
  5004. FreeParamValueList(o);
  5005. return ret;
  5006. }
  5007. // Export the connection settings
  5008. UINT PcAccountExport(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  5009. {
  5010. LIST *o;
  5011. PC *pc = (PC *)param;
  5012. UINT ret = ERR_NO_ERROR;
  5013. RPC_CLIENT_GET_ACCOUNT t;
  5014. // Parameter list that can be specified
  5015. PARAM args[] =
  5016. {
  5017. {"[name]", CmdPrompt, _UU("CMD_AccountCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  5018. {"SAVEPATH", CmdPrompt, _UU("CMD_AccountExport_PROMPT_SAVEPATH"), CmdEvalNotEmpty, NULL},
  5019. };
  5020. // Get the parameter list
  5021. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  5022. if (o == NULL)
  5023. {
  5024. return ERR_INVALID_PARAMETER;
  5025. }
  5026. // RPC call
  5027. Zero(&t, sizeof(t));
  5028. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  5029. ret = CcGetAccount(pc->RemoteClient, &t);
  5030. if (ret == ERR_NO_ERROR)
  5031. {
  5032. RPC_CLIENT_CREATE_ACCOUNT z;
  5033. BUF *b;
  5034. BUF *b2;
  5035. char tmp[MAX_SIZE];
  5036. UCHAR *buf;
  5037. UINT buf_size;
  5038. UCHAR bom[] = {0xef, 0xbb, 0xbf, };
  5039. Zero(&z, sizeof(z));
  5040. z.CheckServerCert = t.CheckServerCert;
  5041. z.ClientAuth = t.ClientAuth;
  5042. z.ClientOption = t.ClientOption;
  5043. z.ServerCert = t.ServerCert;
  5044. z.StartupAccount = t.StartupAccount;
  5045. b = CiAccountToCfg(&z);
  5046. StrCpy(tmp, sizeof(tmp), GetParamStr(o, "SAVEPATH"));
  5047. b2 = NewBuf();
  5048. WriteBuf(b2, bom, sizeof(bom));
  5049. // Add the header part
  5050. buf_size = CalcUniToUtf8(_UU("CM_ACCOUNT_FILE_BANNER"));
  5051. buf = ZeroMalloc(buf_size + 32);
  5052. UniToUtf8(buf, buf_size, _UU("CM_ACCOUNT_FILE_BANNER"));
  5053. WriteBuf(b2, buf, StrLen((char *)buf));
  5054. WriteBuf(b2, b->Buf, b->Size);
  5055. SeekBuf(b2, 0, 0);
  5056. FreeBuf(b);
  5057. if (DumpBuf(b2, tmp) == false)
  5058. {
  5059. c->Write(c, _UU("CMD_SAVEFILE_FAILED"));
  5060. ret = ERR_INTERNAL_ERROR;
  5061. }
  5062. FreeBuf(b2);
  5063. Free(buf);
  5064. }
  5065. if (ret != ERR_NO_ERROR)
  5066. {
  5067. // Error has occurred
  5068. CmdPrintError(c, ret);
  5069. }
  5070. CiFreeClientGetAccount(&t);
  5071. // Release of the parameter list
  5072. FreeParamValueList(o);
  5073. return ret;
  5074. }
  5075. // Check whether the specified account name exists
  5076. bool CmdIsAccountName(REMOTE_CLIENT *r, wchar_t *name)
  5077. {
  5078. UINT i;
  5079. RPC_CLIENT_ENUM_ACCOUNT t;
  5080. wchar_t tmp[MAX_SIZE];
  5081. bool b = false;
  5082. // Validate arguments
  5083. if (r == NULL || name == NULL)
  5084. {
  5085. return false;
  5086. }
  5087. if (CcEnumAccount(r, &t) != ERR_NO_ERROR)
  5088. {
  5089. return false;
  5090. }
  5091. UniStrCpy(tmp, sizeof(tmp), name);
  5092. UniTrim(tmp);
  5093. for (i = 0;i < t.NumItem;i++)
  5094. {
  5095. if (UniStrCmpi(t.Items[i]->AccountName, tmp) == 0)
  5096. {
  5097. b = true;
  5098. break;
  5099. }
  5100. }
  5101. CiFreeClientEnumAccount(&t);
  5102. return b;
  5103. }
  5104. // Generate an import name
  5105. void CmdGenerateImportName(REMOTE_CLIENT *r, wchar_t *name, UINT size, wchar_t *old_name)
  5106. {
  5107. UINT i;
  5108. // Validate arguments
  5109. if (r == NULL || name == NULL || old_name == NULL)
  5110. {
  5111. return;
  5112. }
  5113. for (i = 1;;i++)
  5114. {
  5115. wchar_t tmp[MAX_SIZE];
  5116. if (i == 1)
  5117. {
  5118. UniFormat(tmp, sizeof(tmp), _UU("CM_IMPORT_NAME_1"), old_name);
  5119. }
  5120. else
  5121. {
  5122. UniFormat(tmp, sizeof(tmp), _UU("CM_IMPORT_NAME_2"), old_name, i);
  5123. }
  5124. if (CmdIsAccountName(r, tmp) == false)
  5125. {
  5126. UniStrCpy(name, size, tmp);
  5127. return;
  5128. }
  5129. }
  5130. }
  5131. // Import a connection setting
  5132. UINT PcAccountImport(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  5133. {
  5134. LIST *o;
  5135. PC *pc = (PC *)param;
  5136. UINT ret = ERR_NO_ERROR;
  5137. BUF *b;
  5138. wchar_t name[MAX_SIZE];
  5139. // Parameter list that can be specified
  5140. PARAM args[] =
  5141. {
  5142. {"[path]", CmdPrompt, _UU("CMD_AccountImport_PROMPT_PATH"), CmdEvalIsFile, NULL},
  5143. };
  5144. // Get the parameter list
  5145. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  5146. if (o == NULL)
  5147. {
  5148. return ERR_INVALID_PARAMETER;
  5149. }
  5150. // Read the file
  5151. b = ReadDumpW(GetParamUniStr(o, "[path]"));
  5152. if (b == NULL)
  5153. {
  5154. // Read failure
  5155. c->Write(c, _UU("CMD_LOADFILE_FAILED"));
  5156. ret = ERR_INTERNAL_ERROR;
  5157. }
  5158. else
  5159. {
  5160. RPC_CLIENT_CREATE_ACCOUNT *t;
  5161. t = CiCfgToAccount(b);
  5162. if (t == NULL)
  5163. {
  5164. // Failed to parse
  5165. c->Write(c, _UU("CMD_AccountImport_FAILED_PARSE"));
  5166. ret = ERR_INTERNAL_ERROR;
  5167. }
  5168. else
  5169. {
  5170. CmdGenerateImportName(pc->RemoteClient, name, sizeof(name), t->ClientOption->AccountName);
  5171. UniStrCpy(t->ClientOption->AccountName, sizeof(t->ClientOption->AccountName), name);
  5172. ret = CcCreateAccount(pc->RemoteClient, t);
  5173. if (ret == ERR_NO_ERROR)
  5174. {
  5175. wchar_t tmp[MAX_SIZE];
  5176. UniFormat(tmp, sizeof(tmp), _UU("CMD_AccountImport_OK"), name);
  5177. c->Write(c, tmp);
  5178. }
  5179. CiFreeClientCreateAccount(t);
  5180. Free(t);
  5181. }
  5182. FreeBuf(b);
  5183. }
  5184. if (ret != ERR_NO_ERROR)
  5185. {
  5186. // Error has occurred
  5187. CmdPrintError(c, ret);
  5188. }
  5189. // Release of the parameter list
  5190. FreeParamValueList(o);
  5191. return ret;
  5192. }
  5193. // Allow remote management of the VPN Client Service
  5194. UINT PcRemoteEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  5195. {
  5196. LIST *o;
  5197. PC *pc = (PC *)param;
  5198. UINT ret = ERR_NO_ERROR;
  5199. CLIENT_CONFIG t;
  5200. // Get the parameter list
  5201. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  5202. if (o == NULL)
  5203. {
  5204. return ERR_INVALID_PARAMETER;
  5205. }
  5206. // RPC call
  5207. Zero(&t, sizeof(t));
  5208. ret = CcGetClientConfig(pc->RemoteClient, &t);
  5209. if (ret == ERR_NO_ERROR)
  5210. {
  5211. t.AllowRemoteConfig = true;
  5212. ret = CcSetClientConfig(pc->RemoteClient, &t);
  5213. }
  5214. if (ret == ERR_NO_ERROR)
  5215. {
  5216. // Success
  5217. }
  5218. if (ret != ERR_NO_ERROR)
  5219. {
  5220. // Error has occurred
  5221. CmdPrintError(c, ret);
  5222. }
  5223. // Release of the parameter list
  5224. FreeParamValueList(o);
  5225. return ret;
  5226. }
  5227. // Prohibit remote management of the VPN Client Service
  5228. UINT PcRemoteDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  5229. {
  5230. LIST *o;
  5231. PC *pc = (PC *)param;
  5232. UINT ret = ERR_NO_ERROR;
  5233. CLIENT_CONFIG t;
  5234. // Get the parameter list
  5235. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  5236. if (o == NULL)
  5237. {
  5238. return ERR_INVALID_PARAMETER;
  5239. }
  5240. // RPC call
  5241. Zero(&t, sizeof(t));
  5242. ret = CcGetClientConfig(pc->RemoteClient, &t);
  5243. if (ret == ERR_NO_ERROR)
  5244. {
  5245. t.AllowRemoteConfig = false;
  5246. ret = CcSetClientConfig(pc->RemoteClient, &t);
  5247. }
  5248. if (ret == ERR_NO_ERROR)
  5249. {
  5250. // Success
  5251. }
  5252. if (ret != ERR_NO_ERROR)
  5253. {
  5254. // Error has occurred
  5255. CmdPrintError(c, ret);
  5256. }
  5257. // Release of the parameter list
  5258. FreeParamValueList(o);
  5259. return ret;
  5260. }
  5261. // Enable the maintenance function of the Internet connection
  5262. UINT PcKeepEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  5263. {
  5264. LIST *o;
  5265. PC *pc = (PC *)param;
  5266. UINT ret = ERR_NO_ERROR;
  5267. CLIENT_CONFIG t;
  5268. // Get the parameter list
  5269. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  5270. if (o == NULL)
  5271. {
  5272. return ERR_INVALID_PARAMETER;
  5273. }
  5274. // RPC call
  5275. Zero(&t, sizeof(t));
  5276. ret = CcGetClientConfig(pc->RemoteClient, &t);
  5277. if (ret == ERR_NO_ERROR)
  5278. {
  5279. // Change the settings
  5280. t.UseKeepConnect = true;
  5281. ret = CcSetClientConfig(pc->RemoteClient, &t);
  5282. }
  5283. if (ret == ERR_NO_ERROR)
  5284. {
  5285. // Success
  5286. }
  5287. if (ret != ERR_NO_ERROR)
  5288. {
  5289. // Error has occurred
  5290. CmdPrintError(c, ret);
  5291. }
  5292. // Release of the parameter list
  5293. FreeParamValueList(o);
  5294. return ret;
  5295. }
  5296. // Disable the maintenance function of the Internet connection
  5297. UINT PcKeepDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  5298. {
  5299. LIST *o;
  5300. PC *pc = (PC *)param;
  5301. UINT ret = ERR_NO_ERROR;
  5302. CLIENT_CONFIG t;
  5303. // Get the parameter list
  5304. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  5305. if (o == NULL)
  5306. {
  5307. return ERR_INVALID_PARAMETER;
  5308. }
  5309. // RPC call
  5310. Zero(&t, sizeof(t));
  5311. ret = CcGetClientConfig(pc->RemoteClient, &t);
  5312. if (ret == ERR_NO_ERROR)
  5313. {
  5314. // Change the settings
  5315. t.UseKeepConnect = false;
  5316. ret = CcSetClientConfig(pc->RemoteClient, &t);
  5317. }
  5318. if (ret == ERR_NO_ERROR)
  5319. {
  5320. // Success
  5321. }
  5322. if (ret != ERR_NO_ERROR)
  5323. {
  5324. // Error has occurred
  5325. CmdPrintError(c, ret);
  5326. }
  5327. // Release of the parameter list
  5328. FreeParamValueList(o);
  5329. return ret;
  5330. }
  5331. // Set the maintenance function of the Internet connection
  5332. UINT PcKeepSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  5333. {
  5334. LIST *o;
  5335. PC *pc = (PC *)param;
  5336. UINT ret = ERR_NO_ERROR;
  5337. CLIENT_CONFIG t;
  5338. char *host;
  5339. UINT port;
  5340. // Parameter list that can be specified
  5341. PARAM args[] =
  5342. {
  5343. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  5344. {"HOST", CmdPrompt, _UU("CMD_KeepSet_PROMPT_HOST"), CmdEvalHostAndPort, NULL},
  5345. {"PROTOCOL", CmdPrompt, _UU("CMD_KeepSet_PROMPT_PROTOCOL"), CmdEvalTcpOrUdp, NULL},
  5346. {"INTERVAL", CmdPrompt, _UU("CMD_KeepSet_PROMPT_INTERVAL"), NULL, NULL},
  5347. };
  5348. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  5349. if (o == NULL)
  5350. {
  5351. return ERR_INVALID_PARAMETER;
  5352. }
  5353. // RPC call
  5354. Zero(&t, sizeof(t));
  5355. ret = CcGetClientConfig(pc->RemoteClient, &t);
  5356. if (ret == ERR_NO_ERROR)
  5357. {
  5358. if (ParseHostPort(GetParamStr(o, "HOST"), &host, &port, 0))
  5359. {
  5360. StrCpy(t.KeepConnectHost, sizeof(t.KeepConnectHost), host);
  5361. t.KeepConnectPort = port;
  5362. t.KeepConnectInterval = GetParamInt(o, "INTERVAL");
  5363. t.KeepConnectProtocol = (StrCmpi(GetParamStr(o, "PROTOCOL"), "tcp") == 0) ? 0 : 1;
  5364. Free(host);
  5365. ret = CcSetClientConfig(pc->RemoteClient, &t);
  5366. }
  5367. }
  5368. if (ret != ERR_NO_ERROR)
  5369. {
  5370. // Error has occurred
  5371. CmdPrintError(c, ret);
  5372. }
  5373. // Release of the parameter list
  5374. FreeParamValueList(o);
  5375. return ret;
  5376. }
  5377. // Get the maintenance function of the Internet connection
  5378. UINT PcKeepGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  5379. {
  5380. LIST *o;
  5381. PC *pc = (PC *)param;
  5382. UINT ret = ERR_NO_ERROR;
  5383. CLIENT_CONFIG t;
  5384. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  5385. if (o == NULL)
  5386. {
  5387. return ERR_INVALID_PARAMETER;
  5388. }
  5389. // RPC call
  5390. Zero(&t, sizeof(t));
  5391. ret = CcGetClientConfig(pc->RemoteClient, &t);
  5392. if (ret == ERR_NO_ERROR)
  5393. {
  5394. wchar_t tmp[MAX_SIZE];
  5395. CT *ct = CtNewStandard();
  5396. StrToUni(tmp, sizeof(tmp), t.KeepConnectHost);
  5397. CtInsert(ct, _UU("CMD_KeepGet_COLUMN_1"), tmp);
  5398. UniToStru(tmp, t.KeepConnectPort);
  5399. CtInsert(ct, _UU("CMD_KeepGet_COLUMN_2"), tmp);
  5400. UniToStru(tmp, t.KeepConnectInterval);
  5401. CtInsert(ct, _UU("CMD_KeepGet_COLUMN_3"), tmp);
  5402. CtInsert(ct, _UU("CMD_KeepGet_COLUMN_4"),
  5403. t.KeepConnectProtocol == 0 ? L"TCP/IP" : L"UDP/IP");
  5404. CtInsert(ct, _UU("CMD_KeepGet_COLUMN_5"),
  5405. t.UseKeepConnect ? _UU("SM_ACCESS_ENABLE") : _UU("SM_ACCESS_DISABLE"));
  5406. CtFree(ct, c);
  5407. }
  5408. if (ret != ERR_NO_ERROR)
  5409. {
  5410. // Error has occurred
  5411. CmdPrintError(c, ret);
  5412. }
  5413. // Release of the parameter list
  5414. FreeParamValueList(o);
  5415. return ret;
  5416. }
  5417. // Creat a new client management tool context
  5418. PC *NewPc(CONSOLE *c, REMOTE_CLIENT *remote_client, char *servername, wchar_t *cmdline)
  5419. {
  5420. PC *pc;
  5421. // Validate arguments
  5422. if (c == NULL || remote_client == NULL || servername == NULL)
  5423. {
  5424. return NULL;
  5425. }
  5426. if (UniIsEmptyStr(cmdline))
  5427. {
  5428. cmdline = NULL;
  5429. }
  5430. pc = ZeroMalloc(sizeof(PC));
  5431. pc->ConsoleForServer = false;
  5432. pc->ServerName = CopyStr(servername);
  5433. pc->Console = c;
  5434. pc->LastError = 0;
  5435. pc->RemoteClient = remote_client;
  5436. pc->CmdLine = CopyUniStr(cmdline);
  5437. return pc;
  5438. }
  5439. // Release the client management tools context
  5440. void FreePc(PC *pc)
  5441. {
  5442. // Validate arguments
  5443. if (pc == NULL)
  5444. {
  5445. return;
  5446. }
  5447. Free(pc->ServerName);
  5448. Free(pc->CmdLine);
  5449. Free(pc);
  5450. }
  5451. // Client management tool
  5452. UINT PcConnect(CONSOLE *c, char *target, wchar_t *cmdline, char *password)
  5453. {
  5454. CEDAR *cedar;
  5455. REMOTE_CLIENT *client;
  5456. bool bad_pass;
  5457. bool no_remote;
  5458. char pass[MAX_SIZE];
  5459. UINT ret = 0;
  5460. // Validate arguments
  5461. if (c == NULL || target == NULL)
  5462. {
  5463. return ERR_INTERNAL_ERROR;
  5464. }
  5465. StrCpy(pass, sizeof(pass), password);
  5466. cedar = NewCedar(NULL, NULL);
  5467. RETRY:
  5468. client = CcConnectRpc(target, pass, &bad_pass, &no_remote, 0);
  5469. if (client == NULL)
  5470. {
  5471. if (no_remote)
  5472. {
  5473. // Remote connection refusal
  5474. c->Write(c, _UU("CMD_VPNCMD_CLIENT_NO_REMODE"));
  5475. ReleaseCedar(cedar);
  5476. return ERR_INTERNAL_ERROR;
  5477. }
  5478. else if (bad_pass)
  5479. {
  5480. char *tmp;
  5481. // Password is different
  5482. c->Write(c, _UU("CMD_VPNCMD_PASSWORD_1"));
  5483. tmp = c->ReadPassword(c, _UU("CMD_VPNCMD_PASSWORD_2"));
  5484. c->Write(c, L"");
  5485. if (tmp == NULL)
  5486. {
  5487. // Cancel
  5488. ReleaseCedar(cedar);
  5489. return ERR_ACCESS_DENIED;
  5490. }
  5491. else
  5492. {
  5493. StrCpy(pass, sizeof(pass), tmp);
  5494. Free(tmp);
  5495. }
  5496. goto RETRY;
  5497. }
  5498. else
  5499. {
  5500. // Connection failure
  5501. CmdPrintError(c, ERR_CONNECT_FAILED);
  5502. ReleaseCedar(cedar);
  5503. return ERR_CONNECT_FAILED;
  5504. }
  5505. }
  5506. else
  5507. {
  5508. // Connection complete
  5509. PC *pc = NewPc(c, client, target, cmdline);
  5510. PcMain(pc);
  5511. ret = pc->LastError;
  5512. FreePc(pc);
  5513. }
  5514. CcDisconnectRpc(client);
  5515. ReleaseCedar(cedar);
  5516. return ret;
  5517. }
  5518. // Server Administration Tool Processor Main
  5519. void PsMain(PS *ps)
  5520. {
  5521. char prompt[MAX_SIZE];
  5522. wchar_t tmp[MAX_SIZE];
  5523. // Validate arguments
  5524. if (ps == NULL)
  5525. {
  5526. return;
  5527. }
  5528. // If it's not in CSV mode, to display a message that the connection has been made
  5529. if(ps->Console->ConsoleType != CONSOLE_CSV)
  5530. {
  5531. UniFormat(tmp, sizeof(tmp), _UU("CMD_VPNCMD_SERVER_CONNECTED"),
  5532. ps->ServerName, ps->ServerPort);
  5533. ps->Console->Write(ps->Console, tmp);
  5534. ps->Console->Write(ps->Console, L"");
  5535. if (ps->HubName == NULL)
  5536. {
  5537. // Server management mode
  5538. ps->Console->Write(ps->Console, _UU("CMD_VPNCMD_SERVER_CONNECTED_1"));
  5539. }
  5540. else
  5541. {
  5542. // Virtual HUB management mode
  5543. UniFormat(tmp, sizeof(tmp), _UU("CMD_VPNCMD_SERVER_CONNECTED_2"),
  5544. ps->HubName);
  5545. ps->Console->Write(ps->Console, tmp);
  5546. }
  5547. ps->Console->Write(ps->Console, L"");
  5548. }
  5549. // Get the Caps
  5550. ps->CapsList = ScGetCapsEx(ps->Rpc);
  5551. if (ps->AdminHub != NULL)
  5552. {
  5553. RPC_HUB_STATUS t;
  5554. UINT ret;
  5555. wchar_t tmp[MAX_SIZE];
  5556. // Choose the Virtual HUB that is specified in the ADMINHUB
  5557. Zero(&t, sizeof(t));
  5558. StrCpy(t.HubName, sizeof(t.HubName), ps->AdminHub);
  5559. ret = ScGetHubStatus(ps->Rpc, &t);
  5560. if (ret == ERR_NO_ERROR)
  5561. {
  5562. // Success
  5563. UniFormat(tmp, sizeof(tmp), _UU("CMD_Hub_Selected"), t.HubName);
  5564. if (ps->HubName != NULL)
  5565. {
  5566. Free(ps->HubName);
  5567. }
  5568. ps->HubName = CopyStr(t.HubName);
  5569. if( ps->Console->ConsoleType != CONSOLE_CSV)
  5570. {
  5571. ps->Console->Write(ps->Console, tmp);
  5572. }
  5573. }
  5574. else
  5575. {
  5576. // Failure
  5577. UniFormat(tmp, sizeof(tmp), _UU("CMD_Hub_Select_Failed"), ps->AdminHub);
  5578. ps->Console->Write(ps->Console, tmp);
  5579. CmdPrintError(ps->Console, ret);
  5580. }
  5581. }
  5582. if (ps->HubName == NULL)
  5583. {
  5584. RPC_KEY_PAIR t;
  5585. Zero(&t, sizeof(t));
  5586. if (ScGetServerCert(ps->Rpc, &t) == ERR_NO_ERROR)
  5587. {
  5588. if (t.Cert != NULL && t.Cert->has_basic_constraints == false)
  5589. {
  5590. if (t.Cert->root_cert)
  5591. {
  5592. ps->Console->Write(ps->Console, L"");
  5593. ps->Console->Write(ps->Console, _UU("SM_CERT_MESSAGE_CLI"));
  5594. ps->Console->Write(ps->Console, L"");
  5595. }
  5596. }
  5597. FreeRpcKeyPair(&t);
  5598. }
  5599. }
  5600. while (true)
  5601. {
  5602. // Definition of command
  5603. CMD cmd[] =
  5604. {
  5605. {"About", PsAbout},
  5606. {"Check", PtCheck},
  5607. {"Crash", PsCrash},
  5608. {"Flush", PsFlush},
  5609. {"Debug", PsDebug},
  5610. {"ServerInfoGet", PsServerInfoGet},
  5611. {"ServerStatusGet", PsServerStatusGet},
  5612. {"ListenerCreate", PsListenerCreate},
  5613. {"ListenerDelete", PsListenerDelete},
  5614. {"ListenerList", PsListenerList},
  5615. {"ListenerEnable", PsListenerEnable},
  5616. {"ListenerDisable", PsListenerDisable},
  5617. {"ServerPasswordSet", PsServerPasswordSet},
  5618. {"ClusterSettingGet", PsClusterSettingGet},
  5619. {"ClusterSettingStandalone", PsClusterSettingStandalone},
  5620. {"ClusterSettingController", PsClusterSettingController},
  5621. {"ClusterSettingMember", PsClusterSettingMember},
  5622. {"ClusterMemberList", PsClusterMemberList},
  5623. {"ClusterMemberInfoGet", PsClusterMemberInfoGet},
  5624. {"ClusterMemberCertGet", PsClusterMemberCertGet},
  5625. {"ClusterConnectionStatusGet", PsClusterConnectionStatusGet},
  5626. {"ServerCertGet", PsServerCertGet},
  5627. {"ServerKeyGet", PsServerKeyGet},
  5628. {"ServerCertSet", PsServerCertSet},
  5629. {"ServerCipherGet", PsServerCipherGet},
  5630. {"ServerCipherSet", PsServerCipherSet},
  5631. {"KeepEnable", PsKeepEnable},
  5632. {"KeepDisable", PsKeepDisable},
  5633. {"KeepSet", PsKeepSet},
  5634. {"KeepGet", PsKeepGet},
  5635. {"SyslogGet", PsSyslogGet},
  5636. {"SyslogDisable", PsSyslogDisable},
  5637. {"SyslogEnable", PsSyslogEnable},
  5638. {"ConnectionList", PsConnectionList},
  5639. {"ConnectionGet", PsConnectionGet},
  5640. {"ConnectionDisconnect", PsConnectionDisconnect},
  5641. {"BridgeDeviceList", PsBridgeDeviceList},
  5642. {"BridgeList", PsBridgeList},
  5643. {"BridgeCreate", PsBridgeCreate},
  5644. {"BridgeDelete", PsBridgeDelete},
  5645. {"Caps", PsCaps},
  5646. {"Reboot", PsReboot},
  5647. {"ConfigGet", PsConfigGet},
  5648. {"ConfigSet", PsConfigSet},
  5649. {"RouterList", PsRouterList},
  5650. {"RouterAdd", PsRouterAdd},
  5651. {"RouterDelete", PsRouterDelete},
  5652. {"RouterStart", PsRouterStart},
  5653. {"RouterStop", PsRouterStop},
  5654. {"RouterIfList", PsRouterIfList},
  5655. {"RouterIfAdd", PsRouterIfAdd},
  5656. {"RouterIfDel", PsRouterIfDel},
  5657. {"RouterTableList", PsRouterTableList},
  5658. {"RouterTableAdd", PsRouterTableAdd},
  5659. {"RouterTableDel", PsRouterTableDel},
  5660. {"LogFileList", PsLogFileList},
  5661. {"LogFileGet", PsLogFileGet},
  5662. {"HubCreate", PsHubCreate},
  5663. {"HubCreateDynamic", PsHubCreateDynamic},
  5664. {"HubCreateStatic", PsHubCreateStatic},
  5665. {"HubDelete", PsHubDelete},
  5666. {"HubSetStatic", PsHubSetStatic},
  5667. {"HubSetDynamic", PsHubSetDynamic},
  5668. {"HubList", PsHubList},
  5669. {"Hub", PsHub},
  5670. {"Online", PsOnline},
  5671. {"Offline", PsOffline},
  5672. {"SetMaxSession", PsSetMaxSession},
  5673. {"SetHubPassword", PsSetHubPassword},
  5674. {"SetEnumAllow", PsSetEnumAllow},
  5675. {"SetEnumDeny", PsSetEnumDeny},
  5676. {"OptionsGet", PsOptionsGet},
  5677. {"RadiusServerSet", PsRadiusServerSet},
  5678. {"RadiusServerDelete", PsRadiusServerDelete},
  5679. {"RadiusServerGet", PsRadiusServerGet},
  5680. {"StatusGet", PsStatusGet},
  5681. {"LogGet", PsLogGet},
  5682. {"LogEnable", PsLogEnable},
  5683. {"LogDisable", PsLogDisable},
  5684. {"LogSwitchSet", PsLogSwitchSet},
  5685. {"LogPacketSaveType", PsLogPacketSaveType},
  5686. {"CAList", PsCAList},
  5687. {"CAAdd", PsCAAdd},
  5688. {"CADelete", PsCADelete},
  5689. {"CAGet", PsCAGet},
  5690. {"CascadeList", PsCascadeList},
  5691. {"CascadeCreate", PsCascadeCreate},
  5692. {"CascadeSet", PsCascadeSet},
  5693. {"CascadeGet", PsCascadeGet},
  5694. {"CascadeDelete", PsCascadeDelete},
  5695. {"CascadeUsernameSet", PsCascadeUsernameSet},
  5696. {"CascadeAnonymousSet", PsCascadeAnonymousSet},
  5697. {"CascadePasswordSet", PsCascadePasswordSet},
  5698. {"CascadeCertSet", PsCascadeCertSet},
  5699. {"CascadeCertGet", PsCascadeCertGet},
  5700. {"CascadeEncryptEnable", PsCascadeEncryptEnable},
  5701. {"CascadeEncryptDisable", PsCascadeEncryptDisable},
  5702. {"CascadeCompressEnable", PsCascadeCompressEnable},
  5703. {"CascadeCompressDisable", PsCascadeCompressDisable},
  5704. {"CascadeProxyNone", PsCascadeProxyNone},
  5705. {"CascadeProxyHttp", PsCascadeProxyHttp},
  5706. {"CascadeProxySocks", PsCascadeProxySocks},
  5707. {"CascadeServerCertEnable", PsCascadeServerCertEnable},
  5708. {"CascadeServerCertDisable", PsCascadeServerCertDisable},
  5709. {"CascadeServerCertSet", PsCascadeServerCertSet},
  5710. {"CascadeServerCertDelete", PsCascadeServerCertDelete},
  5711. {"CascadeServerCertGet", PsCascadeServerCertGet},
  5712. {"CascadeDetailSet", PsCascadeDetailSet},
  5713. {"CascadePolicySet", PsCascadePolicySet},
  5714. {"PolicyList", PsPolicyList},
  5715. {"CascadeStatusGet", PsCascadeStatusGet},
  5716. {"CascadeRename", PsCascadeRename},
  5717. {"CascadeOnline", PsCascadeOnline},
  5718. {"CascadeOffline", PsCascadeOffline},
  5719. {"AccessAdd", PsAccessAdd},
  5720. {"AccessAddEx", PsAccessAddEx},
  5721. {"AccessAdd6", PsAccessAdd6},
  5722. {"AccessAddEx6", PsAccessAddEx6},
  5723. {"AccessList", PsAccessList},
  5724. {"AccessDelete", PsAccessDelete},
  5725. {"AccessEnable", PsAccessEnable},
  5726. {"AccessDisable", PsAccessDisable},
  5727. {"UserList", PsUserList},
  5728. {"UserCreate", PsUserCreate},
  5729. {"UserSet", PsUserSet},
  5730. {"UserDelete", PsUserDelete},
  5731. {"UserGet", PsUserGet},
  5732. {"UserAnonymousSet", PsUserAnonymousSet},
  5733. {"UserPasswordSet", PsUserPasswordSet},
  5734. {"UserCertSet", PsUserCertSet},
  5735. {"UserCertGet", PsUserCertGet},
  5736. {"UserSignedSet", PsUserSignedSet},
  5737. {"UserRadiusSet", PsUserRadiusSet},
  5738. {"UserNTLMSet", PsUserNTLMSet},
  5739. {"UserPolicyRemove", PsUserPolicyRemove},
  5740. {"UserPolicySet", PsUserPolicySet},
  5741. {"UserExpiresSet", PsUserExpiresSet},
  5742. {"GroupList", PsGroupList},
  5743. {"GroupCreate", PsGroupCreate},
  5744. {"GroupSet", PsGroupSet},
  5745. {"GroupDelete", PsGroupDelete},
  5746. {"GroupGet", PsGroupGet},
  5747. {"GroupJoin", PsGroupJoin},
  5748. {"GroupUnjoin", PsGroupUnjoin},
  5749. {"GroupPolicyRemove", PsGroupPolicyRemove},
  5750. {"GroupPolicySet", PsGroupPolicySet},
  5751. {"SessionList", PsSessionList},
  5752. {"SessionGet", PsSessionGet},
  5753. {"SessionDisconnect", PsSessionDisconnect},
  5754. {"MacTable", PsMacTable},
  5755. {"MacDelete", PsMacDelete},
  5756. {"IpTable", PsIpTable},
  5757. {"IpDelete", PsIpDelete},
  5758. {"SecureNatEnable", PsSecureNatEnable},
  5759. {"SecureNatDisable", PsSecureNatDisable},
  5760. {"SecureNatStatusGet", PsSecureNatStatusGet},
  5761. {"SecureNatHostGet", PsSecureNatHostGet},
  5762. {"SecureNatHostSet", PsSecureNatHostSet},
  5763. {"NatGet", PsNatGet},
  5764. {"NatEnable", PsNatEnable},
  5765. {"NatDisable", PsNatDisable},
  5766. {"NatSet", PsNatSet},
  5767. {"NatTable", PsNatTable},
  5768. {"DhcpGet", PsDhcpGet},
  5769. {"DhcpEnable", PsDhcpEnable},
  5770. {"DhcpDisable", PsDhcpDisable},
  5771. {"DhcpSet", PsDhcpSet},
  5772. {"DhcpTable", PsDhcpTable},
  5773. {"AdminOptionList", PsAdminOptionList},
  5774. {"AdminOptionSet", PsAdminOptionSet},
  5775. {"ExtOptionList", PsExtOptionList},
  5776. {"ExtOptionSet", PsExtOptionSet},
  5777. {"CrlList", PsCrlList},
  5778. {"CrlAdd", PsCrlAdd},
  5779. {"CrlDel", PsCrlDel},
  5780. {"CrlGet", PsCrlGet},
  5781. {"AcList", PsAcList},
  5782. {"AcAdd", PsAcAdd},
  5783. {"AcAdd6", PsAcAdd6},
  5784. {"AcDel", PsAcDel},
  5785. {"MakeCert", PtMakeCert},
  5786. {"MakeCert2048", PtMakeCert2048},
  5787. {"TrafficClient", PtTrafficClient},
  5788. {"TrafficServer", PtTrafficServer},
  5789. {"LicenseAdd", PsLicenseAdd},
  5790. {"LicenseDel", PsLicenseDel},
  5791. {"LicenseList", PsLicenseList},
  5792. {"LicenseStatus", PsLicenseStatus},
  5793. {"IPsecEnable", PsIPsecEnable},
  5794. {"IPsecGet", PsIPsecGet},
  5795. {"EtherIpClientAdd", PsEtherIpClientAdd},
  5796. {"EtherIpClientDelete", PsEtherIpClientDelete},
  5797. {"EtherIpClientList", PsEtherIpClientList},
  5798. {"OpenVpnEnable", PsOpenVpnEnable},
  5799. {"OpenVpnGet", PsOpenVpnGet},
  5800. {"OpenVpnMakeConfig", PsOpenVpnMakeConfig},
  5801. {"SstpEnable", PsSstpEnable},
  5802. {"SstpGet", PsSstpGet},
  5803. {"ServerCertRegenerate", PsServerCertRegenerate},
  5804. {"VpnOverIcmpDnsEnable", PsVpnOverIcmpDnsEnable},
  5805. {"VpnOverIcmpDnsGet", PsVpnOverIcmpDnsGet},
  5806. {"DynamicDnsGetStatus", PsDynamicDnsGetStatus},
  5807. {"DynamicDnsSetHostname", PsDynamicDnsSetHostname},
  5808. {"VpnAzureGetStatus", PsVpnAzureGetStatus},
  5809. {"VpnAzureSetEnable", PsVpnAzureSetEnable},
  5810. };
  5811. // Generate a prompt
  5812. if (ps->HubName == NULL)
  5813. {
  5814. Format(prompt, sizeof(prompt), "VPN Server>");
  5815. }
  5816. else
  5817. {
  5818. Format(prompt, sizeof(prompt), "VPN Server/%s>", ps->HubName);
  5819. }
  5820. if (DispatchNextCmdEx(ps->Console, ps->CmdLine, prompt, cmd, sizeof(cmd) / sizeof(cmd[0]), ps) == false)
  5821. {
  5822. break;
  5823. }
  5824. ps->LastError = ps->Console->RetCode;
  5825. if (ps->LastError == ERR_NO_ERROR && ps->Console->ConsoleType != CONSOLE_CSV)
  5826. {
  5827. ps->Console->Write(ps->Console, _UU("CMD_MSG_OK"));
  5828. ps->Console->Write(ps->Console, L"");
  5829. }
  5830. if (ps->CmdLine != NULL)
  5831. {
  5832. break;
  5833. }
  5834. }
  5835. // Release the Caps
  5836. FreeCapsList(ps->CapsList);
  5837. ps->CapsList = NULL;
  5838. }
  5839. // A template for a new command function
  5840. UINT PsXxx(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  5841. {
  5842. LIST *o;
  5843. PS *ps = (PS *)param;
  5844. UINT ret;
  5845. RPC_LISTENER t;
  5846. PARAM args[] =
  5847. {
  5848. {"[port]", CmdPromptPort, _UU("CMD_ListenerCreate_PortPrompt"), CmdEvalPort, NULL},
  5849. };
  5850. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  5851. if (o == NULL)
  5852. {
  5853. return ERR_INVALID_PARAMETER;
  5854. }
  5855. Zero(&t, sizeof(t));
  5856. t.Enable = true;
  5857. t.Port = ToInt(GetParamStr(o, "[port]"));
  5858. ret = ScCreateListener(ps->Rpc, &t);
  5859. if (ret != ERR_NO_ERROR)
  5860. {
  5861. CmdPrintError(c, ret);
  5862. FreeParamValueList(o);
  5863. return ret;
  5864. }
  5865. FreeParamValueList(o);
  5866. return 0;
  5867. }
  5868. // Set to the stand-alone mode
  5869. UINT PsClusterSettingStandalone(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  5870. {
  5871. LIST *o;
  5872. PS *ps = (PS *)param;
  5873. UINT ret = 0;
  5874. RPC_FARM t;
  5875. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  5876. if (o == NULL)
  5877. {
  5878. return ERR_INVALID_PARAMETER;
  5879. }
  5880. Zero(&t, sizeof(t));
  5881. t.ServerType = SERVER_TYPE_STANDALONE;
  5882. // RPC call
  5883. ret = ScSetFarmSetting(ps->Rpc, &t);
  5884. if (ret != ERR_NO_ERROR)
  5885. {
  5886. // An error has occured
  5887. CmdPrintError(c, ret);
  5888. FreeParamValueList(o);
  5889. return ret;
  5890. }
  5891. FreeParamValueList(o);
  5892. return 0;
  5893. }
  5894. // Set to the cluster controller mode
  5895. UINT PsClusterSettingController(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  5896. {
  5897. LIST *o;
  5898. PS *ps = (PS *)param;
  5899. UINT ret = 0;
  5900. RPC_FARM t;
  5901. UINT weight;
  5902. PARAM args[] =
  5903. {
  5904. {"WEIGHT", NULL, NULL, NULL, NULL},
  5905. {"ONLY", NULL, NULL, NULL, NULL},
  5906. };
  5907. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  5908. if (o == NULL)
  5909. {
  5910. return ERR_INVALID_PARAMETER;
  5911. }
  5912. weight = GetParamInt(o, "WEIGHT");
  5913. if (weight == 0)
  5914. {
  5915. weight = FARM_DEFAULT_WEIGHT;
  5916. }
  5917. Zero(&t, sizeof(t));
  5918. t.ServerType = SERVER_TYPE_FARM_CONTROLLER;
  5919. t.Weight = weight;
  5920. t.ControllerOnly = GetParamYes(o, "ONLY");
  5921. // RPC call
  5922. ret = ScSetFarmSetting(ps->Rpc, &t);
  5923. if (ret != ERR_NO_ERROR)
  5924. {
  5925. // An error has occured
  5926. CmdPrintError(c, ret);
  5927. FreeParamValueList(o);
  5928. return ret;
  5929. }
  5930. FreeParamValueList(o);
  5931. return 0;
  5932. }
  5933. // Evaluate the IP address
  5934. bool CmdEvalIp(CONSOLE *c, wchar_t *str, void *param)
  5935. {
  5936. // Validate arguments
  5937. if (c == NULL || str == NULL)
  5938. {
  5939. return false;
  5940. }
  5941. if (UniIsEmptyStr(str))
  5942. {
  5943. return true;
  5944. }
  5945. if (UniStrToIP32(str) == 0 && UniStrCmpi(str, L"0.0.0.0") != 0)
  5946. {
  5947. wchar_t *msg = (param == NULL) ? _UU("CMD_IP_EVAL_FAILED") : (wchar_t *)param;
  5948. c->Write(c, msg);
  5949. return false;
  5950. }
  5951. return true;
  5952. }
  5953. // Convert a string to port list
  5954. LIST *StrToPortList(char *str)
  5955. {
  5956. LIST *o;
  5957. TOKEN_LIST *t;
  5958. UINT i;
  5959. if (str == NULL)
  5960. {
  5961. return NULL;
  5962. }
  5963. // Convert to token
  5964. t = ParseToken(str, ", ");
  5965. if (t == NULL)
  5966. {
  5967. return NULL;
  5968. }
  5969. if (t->NumTokens == 0)
  5970. {
  5971. FreeToken(t);
  5972. return NULL;
  5973. }
  5974. o = NewListFast(NULL);
  5975. for (i = 0;i < t->NumTokens;i++)
  5976. {
  5977. char *s = t->Token[i];
  5978. UINT n;
  5979. if (IsNum(s) == false)
  5980. {
  5981. ReleaseList(o);
  5982. FreeToken(t);
  5983. return NULL;
  5984. }
  5985. n = ToInt(s);
  5986. if (n == 0 || n >= 65536)
  5987. {
  5988. ReleaseList(o);
  5989. FreeToken(t);
  5990. return NULL;
  5991. }
  5992. if (IsInList(o, (void *)n))
  5993. {
  5994. ReleaseList(o);
  5995. FreeToken(t);
  5996. return NULL;
  5997. }
  5998. Add(o, (void *)n);
  5999. }
  6000. FreeToken(t);
  6001. if (LIST_NUM(o) > MAX_PUBLIC_PORT_NUM)
  6002. {
  6003. ReleaseList(o);
  6004. return NULL;
  6005. }
  6006. return o;
  6007. }
  6008. // Set to the cluster member mode
  6009. UINT PsClusterSettingMember(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6010. {
  6011. LIST *o;
  6012. PS *ps = (PS *)param;
  6013. UINT ret = 0;
  6014. RPC_FARM t;
  6015. char *host_and_port;
  6016. char *host;
  6017. UINT port;
  6018. UINT weight;
  6019. // Parameter list that can be specified
  6020. PARAM args[] =
  6021. {
  6022. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  6023. {"[server:port]", CmdPrompt, _UU("CMD_ClusterSettingMember_Prompt_HOST_1"), CmdEvalHostAndPort, NULL},
  6024. {"IP", PsClusterSettingMemberPromptIp, NULL, CmdEvalIp, NULL},
  6025. {"PORTS", PsClusterSettingMemberPromptPorts, NULL, CmdEvalPortList, NULL},
  6026. {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},
  6027. {"WEIGHT", NULL, NULL, NULL, NULL},
  6028. };
  6029. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  6030. if (o == NULL)
  6031. {
  6032. return ERR_INVALID_PARAMETER;
  6033. }
  6034. weight = GetParamInt(o, "WEIGHT");
  6035. if (weight == 0)
  6036. {
  6037. weight = FARM_DEFAULT_WEIGHT;
  6038. }
  6039. Zero(&t, sizeof(t));
  6040. host_and_port = GetParamStr(o, "[server:port]");
  6041. if (ParseHostPort(host_and_port, &host, &port, 0))
  6042. {
  6043. char *pw;
  6044. char *ports_str;
  6045. LIST *ports;
  6046. UINT i;
  6047. StrCpy(t.ControllerName, sizeof(t.ControllerName), host);
  6048. t.ControllerPort = port;
  6049. Free(host);
  6050. pw = GetParamStr(o, "PASSWORD");
  6051. Hash(t.MemberPassword, pw, StrLen(pw), true);
  6052. t.PublicIp = StrToIP32(GetParamStr(o, "IP"));
  6053. t.ServerType = SERVER_TYPE_FARM_MEMBER;
  6054. ports_str = GetParamStr(o, "PORTS");
  6055. ports = StrToPortList(ports_str);
  6056. t.NumPort = LIST_NUM(ports);
  6057. t.Ports = ZeroMalloc(sizeof(UINT) * t.NumPort);
  6058. for (i = 0;i < t.NumPort;i++)
  6059. {
  6060. t.Ports[i] = (UINT)LIST_DATA(ports, i);
  6061. }
  6062. t.Weight = weight;
  6063. ReleaseList(ports);
  6064. // RPC call
  6065. ret = ScSetFarmSetting(ps->Rpc, &t);
  6066. if (ret != ERR_NO_ERROR)
  6067. {
  6068. // An error has occured
  6069. CmdPrintError(c, ret);
  6070. FreeParamValueList(o);
  6071. return ret;
  6072. }
  6073. FreeRpcFarm(&t);
  6074. }
  6075. FreeParamValueList(o);
  6076. return 0;
  6077. }
  6078. // Evaluate the port list
  6079. bool CmdEvalPortList(CONSOLE *c, wchar_t *str, void *param)
  6080. {
  6081. char *s;
  6082. bool ret = false;
  6083. LIST *o;
  6084. // Validate arguments
  6085. if (c == NULL || str == NULL)
  6086. {
  6087. return false;
  6088. }
  6089. s = CopyUniToStr(str);
  6090. o = StrToPortList(s);
  6091. if (o != NULL)
  6092. {
  6093. ret = true;
  6094. }
  6095. ReleaseList(o);
  6096. Free(s);
  6097. if (ret == false)
  6098. {
  6099. c->Write(c, _UU("CMD_PORTLIST_EVAL_FAILED"));
  6100. }
  6101. return ret;
  6102. }
  6103. // Check the string of the form of the host name and port number
  6104. bool CmdEvalHostAndPort(CONSOLE *c, wchar_t *str, void *param)
  6105. {
  6106. char *tmp;
  6107. bool ret = false;
  6108. // Validate arguments
  6109. if (c == NULL || str == NULL)
  6110. {
  6111. return false;
  6112. }
  6113. tmp = CopyUniToStr(str);
  6114. ret = ParseHostPort(tmp, NULL, NULL, (UINT)param);
  6115. if (ret == false)
  6116. {
  6117. c->Write(c, param == NULL ? _UU("CMD_HOSTPORT_EVAL_FAILED") : (wchar_t *)param);
  6118. }
  6119. Free(tmp);
  6120. return ret;
  6121. }
  6122. // Input the public port number
  6123. wchar_t *PsClusterSettingMemberPromptPorts(CONSOLE *c, void *param)
  6124. {
  6125. wchar_t *ret;
  6126. // Validate arguments
  6127. if (c == NULL)
  6128. {
  6129. return NULL;
  6130. }
  6131. c->Write(c, _UU("CMD_ClusterSettingMember_Prompt_PORT_1"));
  6132. c->Write(c, L"");
  6133. ret = c->ReadLine(c, _UU("CMD_ClusterSettingMember_Prompt_PORT_2"), true);
  6134. return ret;
  6135. }
  6136. // Input the public IP address
  6137. wchar_t *PsClusterSettingMemberPromptIp(CONSOLE *c, void *param)
  6138. {
  6139. wchar_t *ret;
  6140. // Validate arguments
  6141. if (c == NULL)
  6142. {
  6143. return NULL;
  6144. }
  6145. c->Write(c, _UU("CMD_ClusterSettingMember_Prompt_IP_1"));
  6146. c->Write(c, L"");
  6147. ret = c->ReadLine(c, _UU("CMD_ClusterSettingMember_Prompt_IP_2"), true);
  6148. return ret;
  6149. }
  6150. // Show the cluster members list
  6151. UINT PsClusterMemberList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6152. {
  6153. LIST *o;
  6154. PS *ps = (PS *)param;
  6155. UINT ret = 0;
  6156. RPC_ENUM_FARM t;
  6157. CT *ct;
  6158. UINT i;
  6159. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  6160. if (o == NULL)
  6161. {
  6162. return ERR_INVALID_PARAMETER;
  6163. }
  6164. Zero(&t, sizeof(t));
  6165. // RPC call
  6166. ret = ScEnumFarmMember(ps->Rpc, &t);
  6167. if (ret != ERR_NO_ERROR)
  6168. {
  6169. // An error has occured
  6170. CmdPrintError(c, ret);
  6171. FreeParamValueList(o);
  6172. return ret;
  6173. }
  6174. ct = CtNew();
  6175. CtInsertColumn(ct, _UU("CMD_ID"), true);
  6176. CtInsertColumn(ct, _UU("SM_FM_COLUMN_1"), false);
  6177. CtInsertColumn(ct, _UU("SM_FM_COLUMN_2"), false);
  6178. CtInsertColumn(ct, _UU("SM_FM_COLUMN_3"), false);
  6179. CtInsertColumn(ct, _UU("SM_FM_COLUMN_4"), true);
  6180. CtInsertColumn(ct, _UU("SM_FM_COLUMN_5"), true);
  6181. CtInsertColumn(ct, _UU("SM_FM_COLUMN_6"), true);
  6182. CtInsertColumn(ct, _UU("SM_FM_COLUMN_7"), true);
  6183. CtInsertColumn(ct, _UU("SM_FM_COLUMN_8"), true);
  6184. CtInsertColumn(ct, _UU("SM_FM_COLUMN_9"), true);
  6185. for (i = 0;i < t.NumFarm;i++)
  6186. {
  6187. RPC_ENUM_FARM_ITEM *e = &t.Farms[i];
  6188. wchar_t tmp0[64];
  6189. wchar_t tmp1[MAX_SIZE];
  6190. wchar_t tmp2[MAX_SIZE];
  6191. wchar_t tmp3[64];
  6192. wchar_t tmp4[64];
  6193. wchar_t tmp5[64];
  6194. wchar_t tmp6[64];
  6195. wchar_t tmp7[64];
  6196. wchar_t tmp8[64];
  6197. GetDateTimeStrEx64(tmp1, sizeof(tmp1), SystemToLocal64(e->ConnectedTime), NULL);
  6198. StrToUni(tmp2, sizeof(tmp2), e->Hostname);
  6199. UniToStru(tmp3, e->Point);
  6200. UniToStru(tmp4, e->NumSessions);
  6201. UniToStru(tmp5, e->NumTcpConnections);
  6202. UniToStru(tmp6, e->NumHubs);
  6203. UniToStru(tmp7, e->AssignedClientLicense);
  6204. UniToStru(tmp8, e->AssignedBridgeLicense);
  6205. UniToStru(tmp0, e->Id);
  6206. CtInsert(ct, tmp0,
  6207. e->Controller ? _UU("SM_FM_CONTROLLER") : _UU("SM_FM_MEMBER"),
  6208. tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8);
  6209. }
  6210. CtFree(ct, c);
  6211. FreeRpcEnumFarm(&t);
  6212. FreeParamValueList(o);
  6213. return 0;
  6214. }
  6215. // Get information of cluster members
  6216. UINT PsClusterMemberInfoGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6217. {
  6218. LIST *o;
  6219. PS *ps = (PS *)param;
  6220. UINT ret = 0;
  6221. RPC_FARM_INFO t;
  6222. CT *ct;
  6223. // Parameter list that can be specified
  6224. PARAM args[] =
  6225. {
  6226. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  6227. {"[id]", CmdPrompt, _UU("CMD_ClusterMemberInfoGet_PROMPT_ID"), NULL, NULL},
  6228. };
  6229. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  6230. if (o == NULL)
  6231. {
  6232. return ERR_INVALID_PARAMETER;
  6233. }
  6234. Zero(&t, sizeof(t));
  6235. t.Id = UniToInt(GetParamUniStr(o, "[id]"));
  6236. // RPC call
  6237. ret = ScGetFarmInfo(ps->Rpc, &t);
  6238. if (ret != ERR_NO_ERROR)
  6239. {
  6240. // An error has occured
  6241. CmdPrintError(c, ret);
  6242. FreeParamValueList(o);
  6243. return ret;
  6244. }
  6245. ct = CtNewStandard();
  6246. {
  6247. wchar_t tmp[MAX_SIZE];
  6248. char str[MAX_SIZE];
  6249. UINT i;
  6250. CtInsert(ct, _UU("SM_FMINFO_TYPE"),
  6251. t.Controller ? _UU("SM_FARM_CONTROLLER") : _UU("SM_FARM_MEMBER"));
  6252. GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.ConnectedTime), NULL);
  6253. CtInsert(ct, _UU("SM_FMINFO_CONNECT_TIME"), tmp);
  6254. IPToStr32(str, sizeof(str), t.Ip);
  6255. StrToUni(tmp, sizeof(tmp), str);
  6256. CtInsert(ct, _UU("SM_FMINFO_IP"), tmp);
  6257. StrToUni(tmp, sizeof(tmp), t.Hostname);
  6258. CtInsert(ct, _UU("SM_FMINFO_HOSTNAME"), tmp);
  6259. UniToStru(tmp, t.Point);
  6260. CtInsert(ct, _UU("SM_FMINFO_POINT"), tmp);
  6261. UniToStru(tmp, t.Weight);
  6262. CtInsert(ct, _UU("SM_FMINFO_WEIGHT"), tmp);
  6263. UniToStru(tmp, t.NumPort);
  6264. CtInsert(ct, _UU("SM_FMINFO_NUM_PORT"), tmp);
  6265. for (i = 0;i < t.NumPort;i++)
  6266. {
  6267. wchar_t tmp2[MAX_SIZE];
  6268. UniFormat(tmp, sizeof(tmp), _UU("SM_FMINFO_PORT"), i + 1);
  6269. UniToStru(tmp2, t.Ports[i]);
  6270. CtInsert(ct, tmp, tmp2);
  6271. }
  6272. UniToStru(tmp, t.NumFarmHub);
  6273. CtInsert(ct, _UU("SM_FMINFO_NUM_HUB"), tmp);
  6274. for (i = 0;i < t.NumFarmHub;i++)
  6275. {
  6276. wchar_t tmp2[MAX_SIZE];
  6277. UniFormat(tmp, sizeof(tmp), _UU("SM_FMINFO_HUB"), i + 1);
  6278. UniFormat(tmp2, sizeof(tmp2),
  6279. t.FarmHubs[i].DynamicHub ? _UU("SM_FMINFO_HUB_TAG_2") : _UU("SM_FMINFO_HUB_TAG_1"),
  6280. t.FarmHubs[i].HubName);
  6281. CtInsert(ct, tmp, tmp2);
  6282. }
  6283. UniToStru(tmp, t.NumSessions);
  6284. CtInsert(ct, _UU("SM_FMINFO_NUM_SESSION"), tmp);
  6285. UniToStru(tmp, t.NumTcpConnections);
  6286. CtInsert(ct, _UU("SM_FMINFO_NUN_CONNECTION"), tmp);
  6287. }
  6288. CtFree(ct, c);
  6289. FreeRpcFarmInfo(&t);
  6290. FreeParamValueList(o);
  6291. return 0;
  6292. }
  6293. // Get certificates of cluster members
  6294. UINT PsClusterMemberCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6295. {
  6296. LIST *o;
  6297. PS *ps = (PS *)param;
  6298. UINT ret = 0;
  6299. RPC_FARM_INFO t;
  6300. // Parameter list that can be specified
  6301. PARAM args[] =
  6302. {
  6303. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  6304. {"[id]", CmdPrompt, _UU("CMD_ClusterMemberCertGet_PROMPT_ID"), NULL, NULL},
  6305. {"SAVECERT", CmdPrompt, _UU("CMD_SAVECERTPATH"), CmdEvalNotEmpty, NULL},
  6306. };
  6307. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  6308. if (o == NULL)
  6309. {
  6310. return ERR_INVALID_PARAMETER;
  6311. }
  6312. Zero(&t, sizeof(t));
  6313. t.Id = UniToInt(GetParamUniStr(o, "[id]"));
  6314. // RPC call
  6315. ret = ScGetFarmInfo(ps->Rpc, &t);
  6316. if (ret != ERR_NO_ERROR)
  6317. {
  6318. // An error has occured
  6319. CmdPrintError(c, ret);
  6320. FreeParamValueList(o);
  6321. return ret;
  6322. }
  6323. else
  6324. {
  6325. X *x = t.ServerCert;
  6326. wchar_t *filename = GetParamUniStr(o, "SAVECERT");
  6327. if (XToFileW(x, filename, true) == false)
  6328. {
  6329. c->Write(c, _UU("CMD_SAVECERT_FAILED"));
  6330. ret = ERR_INTERNAL_ERROR;
  6331. }
  6332. }
  6333. FreeRpcFarmInfo(&t);
  6334. FreeParamValueList(o);
  6335. return ret;
  6336. }
  6337. // Get the status of the connection to the cluster controller
  6338. UINT PsClusterConnectionStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6339. {
  6340. LIST *o;
  6341. PS *ps = (PS *)param;
  6342. UINT ret = 0;
  6343. RPC_FARM_CONNECTION_STATUS t;
  6344. wchar_t tmp[MAX_SIZE];
  6345. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  6346. if (o == NULL)
  6347. {
  6348. return ERR_INVALID_PARAMETER;
  6349. }
  6350. Zero(&t, sizeof(t));
  6351. // RPC call
  6352. ret = ScGetFarmConnectionStatus(ps->Rpc, &t);
  6353. if (ret != ERR_NO_ERROR)
  6354. {
  6355. // An error has occured
  6356. CmdPrintError(c, ret);
  6357. FreeParamValueList(o);
  6358. return ret;
  6359. }
  6360. else
  6361. {
  6362. CT *ct = CtNewStandard();
  6363. char str[MAX_SIZE];
  6364. if (t.Online == false)
  6365. {
  6366. CtInsert(ct, _UU("SM_FC_IP"), _UU("SM_FC_NOT_CONNECTED"));
  6367. CtInsert(ct, _UU("SM_FC_PORT"), _UU("SM_FC_NOT_CONNECTED"));
  6368. }
  6369. else
  6370. {
  6371. IPToStr32(str, sizeof(str), t.Ip);
  6372. StrToUni(tmp, sizeof(tmp), str);
  6373. CtInsert(ct, _UU("SM_FC_IP"), tmp);
  6374. UniToStru(tmp, t.Port);
  6375. CtInsert(ct, _UU("SM_FC_PORT"), tmp);
  6376. }
  6377. CtInsert(ct,
  6378. _UU("SM_FC_STATUS"),
  6379. t.Online ? _UU("SM_FC_ONLINE") : _UU("SM_FC_OFFLINE"));
  6380. if (t.Online == false)
  6381. {
  6382. UniFormat(tmp, sizeof(tmp), _UU("SM_FC_ERROR_TAG"), _E(t.LastError), t.LastError);
  6383. CtInsert(ct,
  6384. _UU("SM_FC_LAST_ERROR"), tmp);
  6385. }
  6386. GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.StartedTime), NULL);
  6387. CtInsert(ct, _UU("SM_FC_START_TIME"), tmp);
  6388. GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.FirstConnectedTime), NULL);
  6389. CtInsert(ct, _UU("SM_FC_FIRST_TIME"), tmp);
  6390. //if (t.Online == false)
  6391. {
  6392. GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.CurrentConnectedTime), NULL);
  6393. CtInsert(ct, _UU("SM_FC_CURRENT_TIME"), tmp);
  6394. }
  6395. UniToStru(tmp, t.NumTry);
  6396. CtInsert(ct, _UU("SM_FC_NUM_TRY"), tmp);
  6397. UniToStru(tmp, t.NumConnected);
  6398. CtInsert(ct, _UU("SM_FC_NUM_CONNECTED"), tmp);
  6399. UniToStru(tmp, t.NumFailed);
  6400. CtInsert(ct, _UU("SM_FC_NUM_FAILED"), tmp);
  6401. CtFree(ct, c);
  6402. }
  6403. FreeParamValueList(o);
  6404. return 0;
  6405. }
  6406. // Get the SSL certificate of the VPN Server
  6407. UINT PsServerCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6408. {
  6409. LIST *o;
  6410. PS *ps = (PS *)param;
  6411. UINT ret = 0;
  6412. RPC_KEY_PAIR t;
  6413. // Parameter list that can be specified
  6414. PARAM args[] =
  6415. {
  6416. {"[cert]", CmdPrompt, _UU("CMD_SAVECERTPATH"), CmdEvalNotEmpty, NULL},
  6417. };
  6418. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  6419. if (o == NULL)
  6420. {
  6421. return ERR_INVALID_PARAMETER;
  6422. }
  6423. Zero(&t, sizeof(t));
  6424. // RPC call
  6425. ret = ScGetServerCert(ps->Rpc, &t);
  6426. if (ret != ERR_NO_ERROR)
  6427. {
  6428. // An error has occured
  6429. CmdPrintError(c, ret);
  6430. FreeParamValueList(o);
  6431. return ret;
  6432. }
  6433. if (XToFileW(t.Cert, GetParamUniStr(o, "[cert]"), true) == false)
  6434. {
  6435. c->Write(c, _UU("CMD_SAVECERT_FAILED"));
  6436. }
  6437. FreeRpcKeyPair(&t);
  6438. FreeParamValueList(o);
  6439. return 0;
  6440. }
  6441. // Get the private key of the SSL certificate of the VPN Server
  6442. UINT PsServerKeyGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6443. {
  6444. LIST *o;
  6445. PS *ps = (PS *)param;
  6446. UINT ret = 0;
  6447. RPC_KEY_PAIR t;
  6448. // Parameter list that can be specified
  6449. PARAM args[] =
  6450. {
  6451. {"[key]", CmdPrompt, _UU("CMD_SAVEKEYPATH"), CmdEvalNotEmpty, NULL},
  6452. };
  6453. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  6454. if (o == NULL)
  6455. {
  6456. return ERR_INVALID_PARAMETER;
  6457. }
  6458. Zero(&t, sizeof(t));
  6459. // RPC call
  6460. ret = ScGetServerCert(ps->Rpc, &t);
  6461. if (ret != ERR_NO_ERROR)
  6462. {
  6463. // An error has occured
  6464. CmdPrintError(c, ret);
  6465. FreeParamValueList(o);
  6466. return ret;
  6467. }
  6468. if (t.Key != NULL)
  6469. {
  6470. if (KToFileW(t.Key, GetParamUniStr(o, "[key]"), true, NULL) == false)
  6471. {
  6472. c->Write(c, _UU("CMD_SAVEKEY_FAILED"));
  6473. }
  6474. }
  6475. else
  6476. {
  6477. ret = ERR_NOT_ENOUGH_RIGHT;
  6478. CmdPrintError(c, ret);
  6479. }
  6480. FreeRpcKeyPair(&t);
  6481. FreeParamValueList(o);
  6482. return ret;
  6483. }
  6484. // Read the certificate and the private key
  6485. bool CmdLoadCertAndKey(CONSOLE *c, X **xx, K **kk, wchar_t *cert_filename, wchar_t *key_filename)
  6486. {
  6487. X *x;
  6488. K *k;
  6489. // Validate arguments
  6490. if (c == NULL || cert_filename == NULL || key_filename == NULL || xx == NULL || kk == NULL)
  6491. {
  6492. return false;
  6493. }
  6494. x = FileToXW(cert_filename);
  6495. if (x == NULL)
  6496. {
  6497. c->Write(c, _UU("CMD_LOADCERT_FAILED"));
  6498. return false;
  6499. }
  6500. k = CmdLoadKey(c, key_filename);
  6501. if (k == NULL)
  6502. {
  6503. c->Write(c, _UU("CMD_LOADKEY_FAILED"));
  6504. FreeX(x);
  6505. return false;
  6506. }
  6507. if (CheckXandK(x, k) == false)
  6508. {
  6509. c->Write(c, _UU("CMD_KEYPAIR_FAILED"));
  6510. FreeX(x);
  6511. FreeK(k);
  6512. return false;
  6513. }
  6514. *xx = x;
  6515. *kk = k;
  6516. return true;
  6517. }
  6518. // Read the secret key
  6519. K *CmdLoadKey(CONSOLE *c, wchar_t *filename)
  6520. {
  6521. BUF *b;
  6522. // Validate arguments
  6523. if (c == NULL || filename == NULL)
  6524. {
  6525. return NULL;
  6526. }
  6527. b = ReadDumpW(filename);
  6528. if (b == NULL)
  6529. {
  6530. c->Write(c, _UU("CMD_LOADCERT_FAILED"));
  6531. return NULL;
  6532. }
  6533. else
  6534. {
  6535. K *key;
  6536. if (IsEncryptedK(b, true) == false)
  6537. {
  6538. key = BufToK(b, true, IsBase64(b), NULL);
  6539. }
  6540. else
  6541. {
  6542. c->Write(c, _UU("CMD_LOADKEY_ENCRYPTED_1"));
  6543. while (true)
  6544. {
  6545. char *pass = c->ReadPassword(c, _UU("CMD_LOADKEY_ENCRYPTED_2"));
  6546. if (pass == NULL)
  6547. {
  6548. FreeBuf(b);
  6549. return NULL;
  6550. }
  6551. key = BufToK(b, true, IsBase64(b), pass);
  6552. Free(pass);
  6553. if (key != NULL)
  6554. {
  6555. break;
  6556. }
  6557. c->Write(c, _UU("CMD_LOADKEY_ENCRYPTED_3"));
  6558. }
  6559. }
  6560. FreeBuf(b);
  6561. return key;
  6562. }
  6563. }
  6564. // Set the SSL certificate and the private key of the VPN Server
  6565. UINT PsServerCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6566. {
  6567. LIST *o;
  6568. PS *ps = (PS *)param;
  6569. UINT ret = 0;
  6570. RPC_KEY_PAIR t;
  6571. // Parameter list that can be specified
  6572. PARAM args[] =
  6573. {
  6574. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  6575. {"LOADCERT", CmdPrompt, _UU("CMD_LOADCERTPATH"), CmdEvalIsFile, NULL},
  6576. {"LOADKEY", CmdPrompt, _UU("CMD_LOADKEYPATH"), CmdEvalIsFile, NULL},
  6577. };
  6578. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  6579. if (o == NULL)
  6580. {
  6581. return ERR_INVALID_PARAMETER;
  6582. }
  6583. Zero(&t, sizeof(t));
  6584. if (CmdLoadCertAndKey(c, &t.Cert, &t.Key,
  6585. GetParamUniStr(o, "LOADCERT"),
  6586. GetParamUniStr(o, "LOADKEY")))
  6587. {
  6588. // RPC call
  6589. ret = ScSetServerCert(ps->Rpc, &t);
  6590. if (ret != ERR_NO_ERROR)
  6591. {
  6592. // An error has occured
  6593. CmdPrintError(c, ret);
  6594. FreeParamValueList(o);
  6595. return ret;
  6596. }
  6597. if (t.Flag1 == 0)
  6598. {
  6599. // Show the warning message
  6600. c->Write(c, L"");
  6601. c->Write(c, _UU("SM_CERT_NEED_ROOT"));
  6602. c->Write(c, L"");
  6603. }
  6604. FreeRpcKeyPair(&t);
  6605. }
  6606. else
  6607. {
  6608. ret = ERR_INTERNAL_ERROR;
  6609. }
  6610. FreeParamValueList(o);
  6611. return ret;
  6612. }
  6613. // Get the encryption algorithm used for the VPN communication
  6614. UINT PsServerCipherGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6615. {
  6616. LIST *o;
  6617. PS *ps = (PS *)param;
  6618. UINT ret = 0;
  6619. RPC_STR t;
  6620. TOKEN_LIST *ciphers;
  6621. UINT i;
  6622. wchar_t tmp[MAX_SIZE];
  6623. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  6624. if (o == NULL)
  6625. {
  6626. return ERR_INVALID_PARAMETER;
  6627. }
  6628. Zero(&t, sizeof(t));
  6629. // RPC call
  6630. ret = ScGetServerCipher(ps->Rpc, &t);
  6631. if (ret != ERR_NO_ERROR)
  6632. {
  6633. // An error has occured
  6634. CmdPrintError(c, ret);
  6635. FreeParamValueList(o);
  6636. return ret;
  6637. }
  6638. ciphers = GetCipherList();
  6639. c->Write(c, _UU("CMD_ServerCipherGet_SERVER"));
  6640. UniFormat(tmp, sizeof(tmp), L" %S", t.String);
  6641. c->Write(c, tmp);
  6642. c->Write(c, L"");
  6643. c->Write(c, _UU("CMD_ServerCipherGet_CIPHERS"));
  6644. for (i = 0;i < ciphers->NumTokens;i++)
  6645. {
  6646. UniFormat(tmp, sizeof(tmp), L" %S", ciphers->Token[i]);
  6647. c->Write(c, tmp);
  6648. }
  6649. FreeRpcStr(&t);
  6650. FreeParamValueList(o);
  6651. return 0;
  6652. }
  6653. // Set the encryption algorithm used for the VPN communication
  6654. UINT PsServerCipherSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6655. {
  6656. LIST *o;
  6657. PS *ps = (PS *)param;
  6658. UINT ret = 0;
  6659. RPC_STR t;
  6660. // Parameter list that can be specified
  6661. PARAM args[] =
  6662. {
  6663. {"[name]", CmdPrompt, _UU("CMD_ServerCipherSet_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  6664. };
  6665. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  6666. if (o == NULL)
  6667. {
  6668. return ERR_INVALID_PARAMETER;
  6669. }
  6670. Zero(&t, sizeof(t));
  6671. t.String = CopyStr(GetParamStr(o, "[name]"));
  6672. // RPC call
  6673. ret = ScSetServerCipher(ps->Rpc, &t);
  6674. if (ret != ERR_NO_ERROR)
  6675. {
  6676. // An error has occured
  6677. CmdPrintError(c, ret);
  6678. FreeParamValueList(o);
  6679. return ret;
  6680. }
  6681. FreeRpcStr(&t);
  6682. FreeParamValueList(o);
  6683. return 0;
  6684. }
  6685. // Enabling the maintenance function of the Internet connection
  6686. UINT PsKeepEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6687. {
  6688. LIST *o;
  6689. PS *ps = (PS *)param;
  6690. UINT ret = 0;
  6691. RPC_KEEP t;
  6692. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  6693. if (o == NULL)
  6694. {
  6695. return ERR_INVALID_PARAMETER;
  6696. }
  6697. Zero(&t, sizeof(t));
  6698. // RPC call
  6699. ret = ScGetKeep(ps->Rpc, &t);
  6700. if (ret != ERR_NO_ERROR)
  6701. {
  6702. // An error has occured
  6703. CmdPrintError(c, ret);
  6704. FreeParamValueList(o);
  6705. return ret;
  6706. }
  6707. t.UseKeepConnect = true;
  6708. ret = ScSetKeep(ps->Rpc, &t);
  6709. if (ret != ERR_NO_ERROR)
  6710. {
  6711. // An error has occured
  6712. CmdPrintError(c, ret);
  6713. FreeParamValueList(o);
  6714. return ret;
  6715. }
  6716. FreeParamValueList(o);
  6717. return 0;
  6718. }
  6719. // Disabling the maintenance function of the Internet connection
  6720. UINT PsKeepDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6721. {
  6722. LIST *o;
  6723. PS *ps = (PS *)param;
  6724. UINT ret = 0;
  6725. RPC_KEEP t;
  6726. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  6727. if (o == NULL)
  6728. {
  6729. return ERR_INVALID_PARAMETER;
  6730. }
  6731. Zero(&t, sizeof(t));
  6732. // RPC call
  6733. ret = ScGetKeep(ps->Rpc, &t);
  6734. if (ret != ERR_NO_ERROR)
  6735. {
  6736. // An error has occured
  6737. CmdPrintError(c, ret);
  6738. FreeParamValueList(o);
  6739. return ret;
  6740. }
  6741. t.UseKeepConnect = false;
  6742. ret = ScSetKeep(ps->Rpc, &t);
  6743. if (ret != ERR_NO_ERROR)
  6744. {
  6745. // An error has occured
  6746. CmdPrintError(c, ret);
  6747. FreeParamValueList(o);
  6748. return ret;
  6749. }
  6750. FreeParamValueList(o);
  6751. return 0;
  6752. }
  6753. // Evaluate the UDP or the TCP
  6754. bool CmdEvalTcpOrUdp(CONSOLE *c, wchar_t *str, void *param)
  6755. {
  6756. // Validate arguments
  6757. if (c == NULL || str == NULL)
  6758. {
  6759. return false;
  6760. }
  6761. if (UniStrCmpi(str, L"tcp") == 0 || UniStrCmpi(str, L"udp") == 0)
  6762. {
  6763. return true;
  6764. }
  6765. c->Write(c, _UU("CMD_KeepSet_EVAL_TCP_UDP"));
  6766. return false;
  6767. }
  6768. // Enable the syslog configuration
  6769. UINT PsSyslogEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6770. {
  6771. LIST *o;
  6772. PS *ps = (PS *)param;
  6773. UINT ret = 0;
  6774. SYSLOG_SETTING t;
  6775. CMD_EVAL_MIN_MAX minmax = {"CMD_SyslogEnable_MINMAX", 1, 3};
  6776. char *host;
  6777. UINT port;
  6778. // Parameter list that can be specified
  6779. PARAM args[] =
  6780. {
  6781. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  6782. {"[1|2|3]", CmdPrompt, _UU("CMD_SyslogEnable_Prompt_123"), CmdEvalMinMax, &minmax},
  6783. {"HOST", CmdPrompt, _UU("CMD_SyslogEnable_Prompt_HOST"), CmdEvalHostAndPort, (void *)SYSLOG_PORT},
  6784. };
  6785. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  6786. if (o == NULL)
  6787. {
  6788. return ERR_INVALID_PARAMETER;
  6789. }
  6790. Zero(&t, sizeof(t));
  6791. if (ParseHostPort(GetParamStr(o, "HOST"), &host, &port, SYSLOG_PORT))
  6792. {
  6793. StrCpy(t.Hostname, sizeof(t.Hostname), host);
  6794. t.Port = port;
  6795. t.SaveType = GetParamInt(o, "[1|2|3]");
  6796. Free(host);
  6797. // RPC call
  6798. ret = ScSetSysLog(ps->Rpc, &t);
  6799. if (ret != ERR_NO_ERROR)
  6800. {
  6801. // An error has occured
  6802. CmdPrintError(c, ret);
  6803. FreeParamValueList(o);
  6804. return ret;
  6805. }
  6806. }
  6807. FreeParamValueList(o);
  6808. return 0;
  6809. }
  6810. // Disable the syslog configuration
  6811. UINT PsSyslogDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6812. {
  6813. LIST *o;
  6814. PS *ps = (PS *)param;
  6815. UINT ret = 0;
  6816. SYSLOG_SETTING t;
  6817. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  6818. if (o == NULL)
  6819. {
  6820. return ERR_INVALID_PARAMETER;
  6821. }
  6822. Zero(&t, sizeof(t));
  6823. // RPC call
  6824. ret = ScGetSysLog(ps->Rpc, &t);
  6825. if (ret != ERR_NO_ERROR)
  6826. {
  6827. // An error has occured
  6828. CmdPrintError(c, ret);
  6829. FreeParamValueList(o);
  6830. return ret;
  6831. }
  6832. t.SaveType = SYSLOG_NONE;
  6833. // RPC call
  6834. ret = ScSetSysLog(ps->Rpc, &t);
  6835. if (ret != ERR_NO_ERROR)
  6836. {
  6837. // An error has occured
  6838. CmdPrintError(c, ret);
  6839. FreeParamValueList(o);
  6840. return ret;
  6841. }
  6842. FreeParamValueList(o);
  6843. return 0;
  6844. }
  6845. // Get the syslog configuration
  6846. UINT PsSyslogGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6847. {
  6848. LIST *o;
  6849. PS *ps = (PS *)param;
  6850. UINT ret = 0;
  6851. SYSLOG_SETTING t;
  6852. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  6853. if (o == NULL)
  6854. {
  6855. return ERR_INVALID_PARAMETER;
  6856. }
  6857. Zero(&t, sizeof(t));
  6858. // RPC call
  6859. ret = ScGetSysLog(ps->Rpc, &t);
  6860. if (ret != ERR_NO_ERROR)
  6861. {
  6862. // An error has occured
  6863. CmdPrintError(c, ret);
  6864. FreeParamValueList(o);
  6865. return ret;
  6866. }
  6867. else
  6868. {
  6869. wchar_t tmp[MAX_SIZE];
  6870. CT *ct = CtNewStandard();
  6871. CtInsert(ct, _UU("CMD_SyslogGet_COLUMN_1"), GetSyslogSettingName(t.SaveType));
  6872. if (t.SaveType != SYSLOG_NONE)
  6873. {
  6874. StrToUni(tmp, sizeof(tmp), t.Hostname);
  6875. CtInsert(ct, _UU("CMD_SyslogGet_COLUMN_2"), tmp);
  6876. UniToStru(tmp, t.Port);
  6877. CtInsert(ct, _UU("CMD_SyslogGet_COLUMN_3"), tmp);
  6878. }
  6879. CtFree(ct, c);
  6880. }
  6881. FreeParamValueList(o);
  6882. return 0;
  6883. }
  6884. // Get the syslog configuration name
  6885. wchar_t *GetSyslogSettingName(UINT n)
  6886. {
  6887. char tmp[MAX_PATH];
  6888. Format(tmp, sizeof(tmp), "SM_SYSLOG_%u", n);
  6889. return _UU(tmp);
  6890. }
  6891. // Setting of maintenance function of the Internet connection
  6892. UINT PsKeepSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6893. {
  6894. LIST *o;
  6895. PS *ps = (PS *)param;
  6896. UINT ret = 0;
  6897. RPC_KEEP t;
  6898. char *host;
  6899. UINT port;
  6900. // Parameter list that can be specified
  6901. PARAM args[] =
  6902. {
  6903. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  6904. {"HOST", CmdPrompt, _UU("CMD_KeepSet_PROMPT_HOST"), CmdEvalHostAndPort, NULL},
  6905. {"PROTOCOL", CmdPrompt, _UU("CMD_KeepSet_PROMPT_PROTOCOL"), CmdEvalTcpOrUdp, NULL},
  6906. {"INTERVAL", CmdPrompt, _UU("CMD_KeepSet_PROMPT_INTERVAL"), NULL, NULL},
  6907. };
  6908. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  6909. if (o == NULL)
  6910. {
  6911. return ERR_INVALID_PARAMETER;
  6912. }
  6913. Zero(&t, sizeof(t));
  6914. // RPC call
  6915. ret = ScGetKeep(ps->Rpc, &t);
  6916. if (ret != ERR_NO_ERROR)
  6917. {
  6918. // An error has occured
  6919. CmdPrintError(c, ret);
  6920. FreeParamValueList(o);
  6921. return ret;
  6922. }
  6923. if (ParseHostPort(GetParamStr(o, "HOST"), &host, &port, 0))
  6924. {
  6925. StrCpy(t.KeepConnectHost, sizeof(t.KeepConnectHost), host);
  6926. t.KeepConnectPort = port;
  6927. t.KeepConnectInterval = GetParamInt(o, "INTERVAL");
  6928. t.KeepConnectProtocol = (StrCmpi(GetParamStr(o, "PROTOCOL"), "tcp") == 0) ? 0 : 1;
  6929. Free(host);
  6930. // RPC call
  6931. ret = ScSetKeep(ps->Rpc, &t);
  6932. if (ret != ERR_NO_ERROR)
  6933. {
  6934. // An error has occured
  6935. CmdPrintError(c, ret);
  6936. FreeParamValueList(o);
  6937. return ret;
  6938. }
  6939. }
  6940. FreeParamValueList(o);
  6941. return 0;
  6942. }
  6943. // Get the maintenance function of the Internet connection
  6944. UINT PsKeepGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6945. {
  6946. LIST *o;
  6947. PS *ps = (PS *)param;
  6948. UINT ret = 0;
  6949. RPC_KEEP t;
  6950. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  6951. if (o == NULL)
  6952. {
  6953. return ERR_INVALID_PARAMETER;
  6954. }
  6955. Zero(&t, sizeof(t));
  6956. // RPC call
  6957. ret = ScGetKeep(ps->Rpc, &t);
  6958. if (ret != ERR_NO_ERROR)
  6959. {
  6960. // An error has occured
  6961. CmdPrintError(c, ret);
  6962. FreeParamValueList(o);
  6963. return ret;
  6964. }
  6965. else
  6966. {
  6967. wchar_t tmp[MAX_SIZE];
  6968. CT *ct = CtNewStandard();
  6969. StrToUni(tmp, sizeof(tmp), t.KeepConnectHost);
  6970. CtInsert(ct, _UU("CMD_KeepGet_COLUMN_1"), tmp);
  6971. UniToStru(tmp, t.KeepConnectPort);
  6972. CtInsert(ct, _UU("CMD_KeepGet_COLUMN_2"), tmp);
  6973. UniToStru(tmp, t.KeepConnectInterval);
  6974. CtInsert(ct, _UU("CMD_KeepGet_COLUMN_3"), tmp);
  6975. CtInsert(ct, _UU("CMD_KeepGet_COLUMN_4"),
  6976. t.KeepConnectProtocol == 0 ? L"TCP/IP" : L"UDP/IP");
  6977. CtInsert(ct, _UU("CMD_KeepGet_COLUMN_5"),
  6978. t.UseKeepConnect ? _UU("SM_ACCESS_ENABLE") : _UU("SM_ACCESS_DISABLE"));
  6979. CtFree(ct, c);
  6980. }
  6981. FreeParamValueList(o);
  6982. return 0;
  6983. }
  6984. // Get the connection type string
  6985. wchar_t *GetConnectionTypeStr(UINT type)
  6986. {
  6987. char tmp[MAX_SIZE];
  6988. Format(tmp, sizeof(tmp), "SM_CONNECTION_TYPE_%u", type);
  6989. return _UU(tmp);
  6990. }
  6991. // Get the list of TCP connections connected to VPN Server
  6992. UINT PsConnectionList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  6993. {
  6994. LIST *o;
  6995. PS *ps = (PS *)param;
  6996. UINT ret = 0;
  6997. RPC_ENUM_CONNECTION t;
  6998. UINT i;
  6999. CT *ct;
  7000. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  7001. if (o == NULL)
  7002. {
  7003. return ERR_INVALID_PARAMETER;
  7004. }
  7005. Zero(&t, sizeof(t));
  7006. // RPC call
  7007. ret = ScEnumConnection(ps->Rpc, &t);
  7008. if (ret != ERR_NO_ERROR)
  7009. {
  7010. // An error has occured
  7011. CmdPrintError(c, ret);
  7012. FreeParamValueList(o);
  7013. return ret;
  7014. }
  7015. ct = CtNew();
  7016. CtInsertColumn(ct, _UU("SM_CONN_COLUMN_1"), false);
  7017. CtInsertColumn(ct, _UU("SM_CONN_COLUMN_2"), false);
  7018. CtInsertColumn(ct, _UU("SM_CONN_COLUMN_3"), false);
  7019. CtInsertColumn(ct, _UU("SM_CONN_COLUMN_4"), false);
  7020. for (i = 0;i < t.NumConnection;i++)
  7021. {
  7022. wchar_t tmp[MAX_SIZE];
  7023. wchar_t name[MAX_SIZE];
  7024. wchar_t datetime[MAX_SIZE];
  7025. RPC_ENUM_CONNECTION_ITEM *e = &t.Connections[i];
  7026. StrToUni(name, sizeof(name), e->Name);
  7027. UniFormat(tmp, sizeof(tmp), _UU("SM_HOSTNAME_AND_PORT"), e->Hostname, e->Port);
  7028. GetDateTimeStrEx64(datetime, sizeof(datetime), SystemToLocal64(e->ConnectedTime), NULL);
  7029. CtInsert(ct, name, tmp, datetime,
  7030. GetConnectionTypeStr(e->Type));
  7031. }
  7032. CtFree(ct, c);
  7033. FreeRpcEnumConnetion(&t);
  7034. FreeParamValueList(o);
  7035. return 0;
  7036. }
  7037. // Get the TCP connection information currently connected to the VPN Server
  7038. UINT PsConnectionGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7039. {
  7040. LIST *o;
  7041. PS *ps = (PS *)param;
  7042. UINT ret = 0;
  7043. RPC_CONNECTION_INFO t;
  7044. CT *ct;
  7045. wchar_t tmp[MAX_SIZE];
  7046. // Parameter list that can be specified
  7047. PARAM args[] =
  7048. {
  7049. {"[name]", CmdPrompt, _UU("CMD_ConnectionGet_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  7050. };
  7051. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7052. if (o == NULL)
  7053. {
  7054. return ERR_INVALID_PARAMETER;
  7055. }
  7056. Zero(&t, sizeof(t));
  7057. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  7058. // RPC call
  7059. ret = ScGetConnectionInfo(ps->Rpc, &t);
  7060. if (ret != ERR_NO_ERROR)
  7061. {
  7062. // An error has occured
  7063. CmdPrintError(c, ret);
  7064. FreeParamValueList(o);
  7065. return ret;
  7066. }
  7067. else
  7068. {
  7069. ct = CtNewStandard();
  7070. StrToUni(tmp, sizeof(tmp), t.Name);
  7071. CtInsert(ct, _UU("SM_CONNINFO_NAME"), tmp);
  7072. CtInsert(ct, _UU("SM_CONNINFO_TYPE"), GetConnectionTypeStr(t.Type));
  7073. StrToUni(tmp, sizeof(tmp), t.Hostname);
  7074. CtInsert(ct, _UU("SM_CONNINFO_HOSTNAME"), tmp);
  7075. UniToStru(tmp, t.Port);
  7076. CtInsert(ct, _UU("SM_CONNINFO_PORT"), tmp);
  7077. GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.ConnectedTime), NULL);
  7078. CtInsert(ct, _UU("SM_CONNINFO_TIME"), tmp);
  7079. StrToUni(tmp, sizeof(tmp), t.ServerStr);
  7080. CtInsert(ct, _UU("SM_CONNINFO_SERVER_STR"), tmp);
  7081. UniFormat(tmp, sizeof(tmp), L"%u.%02u", t.ServerVer / 100, t.ServerVer % 100);
  7082. CtInsert(ct, _UU("SM_CONNINFO_SERVER_VER"), tmp);
  7083. UniToStru(tmp, t.ServerBuild);
  7084. CtInsert(ct, _UU("SM_CONNINFO_SERVER_BUILD"), tmp);
  7085. if (StrLen(t.ClientStr) != 0)
  7086. {
  7087. StrToUni(tmp, sizeof(tmp), t.ClientStr);
  7088. CtInsert(ct, _UU("SM_CONNINFO_CLIENT_STR"), tmp);
  7089. UniFormat(tmp, sizeof(tmp), L"%u.%02u", t.ClientVer / 100, t.ClientVer % 100);
  7090. CtInsert(ct, _UU("SM_CONNINFO_CLIENT_VER"), tmp);
  7091. UniToStru(tmp, t.ClientBuild);
  7092. CtInsert(ct, _UU("SM_CONNINFO_CLIENT_BUILD"), tmp);
  7093. }
  7094. CtFree(ct, c);
  7095. }
  7096. FreeParamValueList(o);
  7097. return 0;
  7098. }
  7099. // Disconnect the TCP connection connected to the VPN Server
  7100. UINT PsConnectionDisconnect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7101. {
  7102. LIST *o;
  7103. PS *ps = (PS *)param;
  7104. UINT ret = 0;
  7105. RPC_DISCONNECT_CONNECTION t;
  7106. // Parameter list that can be specified
  7107. PARAM args[] =
  7108. {
  7109. {"[name]", CmdPrompt, _UU("CMD_ConnectionDisconnect_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  7110. };
  7111. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7112. if (o == NULL)
  7113. {
  7114. return ERR_INVALID_PARAMETER;
  7115. }
  7116. Zero(&t, sizeof(t));
  7117. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  7118. // RPC call
  7119. ret = ScDisconnectConnection(ps->Rpc, &t);
  7120. if (ret != ERR_NO_ERROR)
  7121. {
  7122. // An error has occured
  7123. CmdPrintError(c, ret);
  7124. FreeParamValueList(o);
  7125. return ret;
  7126. }
  7127. FreeParamValueList(o);
  7128. return 0;
  7129. }
  7130. // Get the LAN card list that can be used for local bridge
  7131. UINT PsBridgeDeviceList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7132. {
  7133. LIST *o;
  7134. PS *ps = (PS *)param;
  7135. UINT ret = 0;
  7136. RPC_ENUM_ETH t;
  7137. UINT i;
  7138. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  7139. if (o == NULL)
  7140. {
  7141. return ERR_INVALID_PARAMETER;
  7142. }
  7143. Zero(&t, sizeof(t));
  7144. // RPC call
  7145. ret = ScEnumEthernet(ps->Rpc, &t);
  7146. if (ret != ERR_NO_ERROR)
  7147. {
  7148. // An error has occured
  7149. CmdPrintError(c, ret);
  7150. FreeParamValueList(o);
  7151. return ret;
  7152. }
  7153. for (i = 0;i < t.NumItem;i++)
  7154. {
  7155. RPC_ENUM_ETH_ITEM *item = &t.Items[i];
  7156. wchar_t tmp[MAX_SIZE * 2];
  7157. StrToUni(tmp, sizeof(tmp), item->DeviceName);
  7158. c->Write(c, tmp);
  7159. }
  7160. FreeRpcEnumEth(&t);
  7161. FreeParamValueList(o);
  7162. return 0;
  7163. }
  7164. // Get the list of local bridge connection
  7165. UINT PsBridgeList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7166. {
  7167. LIST *o;
  7168. PS *ps = (PS *)param;
  7169. UINT ret = 0;
  7170. RPC_ENUM_LOCALBRIDGE t;
  7171. UINT i;
  7172. CT *ct;
  7173. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  7174. if (o == NULL)
  7175. {
  7176. return ERR_INVALID_PARAMETER;
  7177. }
  7178. Zero(&t, sizeof(t));
  7179. // RPC call
  7180. ret = ScEnumLocalBridge(ps->Rpc, &t);
  7181. if (ret != ERR_NO_ERROR)
  7182. {
  7183. // An error has occured
  7184. CmdPrintError(c, ret);
  7185. FreeParamValueList(o);
  7186. return ret;
  7187. }
  7188. ct = CtNew();
  7189. CtInsertColumn(ct, _UU("SM_BRIDGE_COLUMN_1"), false);
  7190. CtInsertColumn(ct, _UU("SM_BRIDGE_COLUMN_2"), false);
  7191. CtInsertColumn(ct, _UU("SM_BRIDGE_COLUMN_3"), false);
  7192. CtInsertColumn(ct, _UU("SM_BRIDGE_COLUMN_4"), false);
  7193. for (i = 0;i < t.NumItem;i++)
  7194. {
  7195. RPC_LOCALBRIDGE *e = &t.Items[i];
  7196. wchar_t name[MAX_SIZE];
  7197. wchar_t nic[MAX_SIZE];
  7198. wchar_t hub[MAX_SIZE];
  7199. wchar_t *status = _UU("SM_BRIDGE_OFFLINE");
  7200. UniToStru(name, i + 1);
  7201. StrToUni(nic, sizeof(nic), e->DeviceName);
  7202. StrToUni(hub, sizeof(hub), e->HubName);
  7203. if (e->Online)
  7204. {
  7205. status = e->Active ? _UU("SM_BRIDGE_ONLINE") : _UU("SM_BRIDGE_ERROR");
  7206. }
  7207. CtInsert(ct, name, hub, nic, status);
  7208. }
  7209. CtFree(ct, c);
  7210. FreeRpcEnumLocalBridge(&t);
  7211. FreeParamValueList(o);
  7212. return 0;
  7213. }
  7214. // Create a local bridge connection
  7215. UINT PsBridgeCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7216. {
  7217. LIST *o;
  7218. PS *ps = (PS *)param;
  7219. UINT ret = 0;
  7220. RPC_LOCALBRIDGE t;
  7221. // Parameter list that can be specified
  7222. PARAM args[] =
  7223. {
  7224. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  7225. {"[hubname]", CmdPrompt, _UU("CMD_BridgeCreate_PROMPT_HUBNAME"), CmdEvalNotEmpty, NULL},
  7226. {"DEVICE", CmdPrompt, _UU("CMD_BridgeCreate_PROMPT_DEVICE"), CmdEvalNotEmpty, NULL},
  7227. {"TAP", NULL, NULL, NULL, NULL},
  7228. };
  7229. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7230. if (o == NULL)
  7231. {
  7232. return ERR_INVALID_PARAMETER;
  7233. }
  7234. Zero(&t, sizeof(t));
  7235. t.Active = true;
  7236. StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "DEVICE"));
  7237. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[hubname]"));
  7238. t.Online = true;
  7239. t.TapMode = GetParamYes(o, "TAP");
  7240. // RPC call
  7241. ret = ScAddLocalBridge(ps->Rpc, &t);
  7242. if (ret != ERR_NO_ERROR)
  7243. {
  7244. // An error has occured
  7245. CmdPrintError(c, ret);
  7246. FreeParamValueList(o);
  7247. return ret;
  7248. }
  7249. else
  7250. {
  7251. c->Write(c, _UU("SM_BRIDGE_INTEL"));
  7252. c->Write(c, L"");
  7253. if (GetCapsBool(ps->CapsList, "b_is_in_vm"))
  7254. {
  7255. // Message in the case of operating in a VM
  7256. c->Write(c, _UU("D_SM_VMBRIDGE@CAPTION"));
  7257. c->Write(c, _UU("D_SM_VMBRIDGE@S_1"));
  7258. c->Write(c, _UU("D_SM_VMBRIDGE@S_2"));
  7259. c->Write(c, L"");
  7260. }
  7261. }
  7262. FreeParamValueList(o);
  7263. return 0;
  7264. }
  7265. // Delete the local bridge connection
  7266. UINT PsBridgeDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7267. {
  7268. LIST *o;
  7269. PS *ps = (PS *)param;
  7270. UINT ret = 0;
  7271. RPC_LOCALBRIDGE t;
  7272. // Parameter list that can be specified
  7273. PARAM args[] =
  7274. {
  7275. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  7276. {"[hubname]", CmdPrompt, _UU("CMD_BridgeDelete_PROMPT_HUBNAME"), CmdEvalNotEmpty, NULL},
  7277. {"DEVICE", CmdPrompt, _UU("CMD_BridgeDelete_PROMPT_DEVICE"), CmdEvalNotEmpty, NULL},
  7278. };
  7279. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7280. if (o == NULL)
  7281. {
  7282. return ERR_INVALID_PARAMETER;
  7283. }
  7284. Zero(&t, sizeof(t));
  7285. StrCpy(t.DeviceName, sizeof(t.DeviceName), GetParamStr(o, "DEVICE"));
  7286. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[hubname]"));
  7287. // RPC call
  7288. ret = ScDeleteLocalBridge(ps->Rpc, &t);
  7289. if (ret != ERR_NO_ERROR)
  7290. {
  7291. // An error has occured
  7292. CmdPrintError(c, ret);
  7293. FreeParamValueList(o);
  7294. return ret;
  7295. }
  7296. FreeParamValueList(o);
  7297. return 0;
  7298. }
  7299. // Get the list of features and capabilities of the server
  7300. UINT PsCaps(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7301. {
  7302. LIST *o;
  7303. PS *ps = (PS *)param;
  7304. UINT ret = 0;
  7305. CAPSLIST *t;
  7306. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  7307. if (o == NULL)
  7308. {
  7309. return ERR_INVALID_PARAMETER;
  7310. }
  7311. // RPC call
  7312. t = ScGetCapsEx(ps->Rpc);
  7313. if (ret != ERR_NO_ERROR)
  7314. {
  7315. // An error has occured
  7316. CmdPrintError(c, ret);
  7317. FreeParamValueList(o);
  7318. return ret;
  7319. }
  7320. else
  7321. {
  7322. UINT i;
  7323. CT *ct;
  7324. ct = CtNewStandard();
  7325. for (i = 0;i < LIST_NUM(t->CapsList);i++)
  7326. {
  7327. CAPS *c = LIST_DATA(t->CapsList, i);
  7328. wchar_t title[MAX_SIZE];
  7329. char name[256];
  7330. Format(name, sizeof(name), "CT_%s", c->Name);
  7331. UniStrCpy(title, sizeof(title), _UU(name));
  7332. if (UniIsEmptyStr(title))
  7333. {
  7334. UniFormat(title, sizeof(title), L"%S", (StrLen(c->Name) >= 2) ? c->Name + 2 : c->Name);
  7335. }
  7336. if (StartWith(c->Name, "b_"))
  7337. {
  7338. bool icon_pass = c->Value == 0 ? false : true;
  7339. if (StrCmpi(c->Name, "b_must_install_pcap") == 0)
  7340. {
  7341. // Reverse only item of WinPcap
  7342. icon_pass = !icon_pass;
  7343. }
  7344. CtInsert(ct, title, c->Value == 0 ? _UU("CAPS_NO") : _UU("CAPS_YES"));
  7345. }
  7346. else
  7347. {
  7348. wchar_t str[64];
  7349. UniToStru(str, c->Value);
  7350. CtInsert(ct, title, str);
  7351. }
  7352. }
  7353. CtFree(ct, c);
  7354. }
  7355. FreeCapsList(t);
  7356. FreeParamValueList(o);
  7357. return 0;
  7358. }
  7359. // Restart the VPN Server service
  7360. UINT PsReboot(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7361. {
  7362. LIST *o;
  7363. PS *ps = (PS *)param;
  7364. UINT ret = 0;
  7365. RPC_TEST t;
  7366. // Parameter list that can be specified
  7367. PARAM args[] =
  7368. {
  7369. {"RESETCONFIG", NULL, NULL, NULL, NULL},
  7370. };
  7371. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7372. if (o == NULL)
  7373. {
  7374. return ERR_INVALID_PARAMETER;
  7375. }
  7376. Zero(&t, sizeof(t));
  7377. t.IntValue = GetParamYes(o, "RESETCONFIG") ? 1 : 0;
  7378. // RPC call
  7379. ret = ScRebootServer(ps->Rpc, &t);
  7380. if (ret != ERR_NO_ERROR)
  7381. {
  7382. // An error has occured
  7383. CmdPrintError(c, ret);
  7384. FreeParamValueList(o);
  7385. return ret;
  7386. }
  7387. FreeRpcTest(&t);
  7388. FreeParamValueList(o);
  7389. return 0;
  7390. }
  7391. // Get the current configuration of the VPN Server
  7392. UINT PsConfigGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7393. {
  7394. LIST *o;
  7395. PS *ps = (PS *)param;
  7396. UINT ret = 0;
  7397. RPC_CONFIG t;
  7398. // Parameter list that can be specified
  7399. PARAM args[] =
  7400. {
  7401. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  7402. {"[path]", NULL, NULL, NULL, NULL},
  7403. };
  7404. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7405. if (o == NULL)
  7406. {
  7407. return ERR_INVALID_PARAMETER;
  7408. }
  7409. Zero(&t, sizeof(t));
  7410. // RPC call
  7411. ret = ScGetConfig(ps->Rpc, &t);
  7412. if (ret != ERR_NO_ERROR)
  7413. {
  7414. // An error has occured
  7415. CmdPrintError(c, ret);
  7416. FreeParamValueList(o);
  7417. return ret;
  7418. }
  7419. else
  7420. {
  7421. wchar_t *filename = GetParamUniStr(o, "[path]");
  7422. if (IsEmptyUniStr(filename))
  7423. {
  7424. // Display on the screen
  7425. wchar_t tmp[MAX_SIZE];
  7426. UINT buf_size;
  7427. wchar_t *buf;
  7428. UNI_TOKEN_LIST *lines;
  7429. UniFormat(tmp, sizeof(tmp), _UU("CMD_ConfigGet_FILENAME"), t.FileName,
  7430. StrLen(t.FileData));
  7431. c->Write(c, tmp);
  7432. c->Write(c, L"");
  7433. buf_size = CalcUtf8ToUni((BYTE *)t.FileData, StrLen(t.FileData));
  7434. buf = ZeroMalloc(buf_size + 32);
  7435. Utf8ToUni(buf, buf_size, (BYTE *)t.FileData, StrLen(t.FileData));
  7436. lines = UniGetLines(buf);
  7437. if (lines != NULL)
  7438. {
  7439. UINT i;
  7440. for (i = 0;i < lines->NumTokens;i++)
  7441. {
  7442. c->Write(c, lines->Token[i]);
  7443. }
  7444. UniFreeToken(lines);
  7445. }
  7446. c->Write(c, L"");
  7447. Free(buf);
  7448. }
  7449. else
  7450. {
  7451. // Save to the file
  7452. IO *io = FileCreateW(filename);
  7453. if (io == NULL)
  7454. {
  7455. c->Write(c, _UU("CMD_ConfigGet_FILE_SAVE_FAILED"));
  7456. ret = ERR_INTERNAL_ERROR;
  7457. }
  7458. else
  7459. {
  7460. FileWrite(io, t.FileData, StrLen(t.FileData));
  7461. FileClose(io);
  7462. }
  7463. }
  7464. }
  7465. FreeRpcConfig(&t);
  7466. FreeParamValueList(o);
  7467. return ret;
  7468. }
  7469. // Write the configuration to the VPN Server
  7470. UINT PsConfigSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7471. {
  7472. LIST *o;
  7473. PS *ps = (PS *)param;
  7474. UINT ret = 0;
  7475. RPC_CONFIG t;
  7476. wchar_t *filename;
  7477. BUF *buf;
  7478. // Parameter list that can be specified
  7479. PARAM args[] =
  7480. {
  7481. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  7482. {"[path]", CmdPrompt, _UU("CMD_ConfigSet_PROMPT_PATH"), CmdEvalIsFile, NULL},
  7483. };
  7484. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7485. if (o == NULL)
  7486. {
  7487. return ERR_INVALID_PARAMETER;
  7488. }
  7489. filename = GetParamUniStr(o, "[path]");
  7490. buf = ReadDumpW(filename);
  7491. if (buf == NULL)
  7492. {
  7493. c->Write(c, _UU("CMD_ConfigSet_FILE_LOAD_FAILED"));
  7494. }
  7495. else
  7496. {
  7497. Zero(&t, sizeof(t));
  7498. t.FileData = ZeroMalloc(buf->Size + 1);
  7499. Copy(t.FileData, buf->Buf, buf->Size);
  7500. FreeBuf(buf);
  7501. // RPC call
  7502. ret = ScSetConfig(ps->Rpc, &t);
  7503. if (ret != ERR_NO_ERROR)
  7504. {
  7505. // An error has occured
  7506. CmdPrintError(c, ret);
  7507. FreeParamValueList(o);
  7508. return ret;
  7509. }
  7510. FreeRpcConfig(&t);
  7511. }
  7512. FreeParamValueList(o);
  7513. return 0;
  7514. }
  7515. // Get the Virtual Layer 3 switch list
  7516. UINT PsRouterList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7517. {
  7518. LIST *o;
  7519. PS *ps = (PS *)param;
  7520. UINT ret = 0;
  7521. RPC_ENUM_L3SW t;
  7522. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  7523. if (o == NULL)
  7524. {
  7525. return ERR_INVALID_PARAMETER;
  7526. }
  7527. Zero(&t, sizeof(t));
  7528. // RPC call
  7529. ret = ScEnumL3Switch(ps->Rpc, &t);
  7530. if (ret != ERR_NO_ERROR)
  7531. {
  7532. // An error has occured
  7533. CmdPrintError(c, ret);
  7534. FreeParamValueList(o);
  7535. return ret;
  7536. }
  7537. else
  7538. {
  7539. CT *ct = CtNew();
  7540. UINT i;
  7541. CtInsertColumn(ct, _UU("SM_L3_SW_COLUMN1"), false);
  7542. CtInsertColumn(ct, _UU("SM_L3_SW_COLUMN2"), false);
  7543. CtInsertColumn(ct, _UU("SM_L3_SW_COLUMN3"), true);
  7544. CtInsertColumn(ct, _UU("SM_L3_SW_COLUMN4"), true);
  7545. for (i = 0;i < t.NumItem;i++)
  7546. {
  7547. RPC_ENUM_L3SW_ITEM *e = &t.Items[i];
  7548. wchar_t tmp1[MAX_SIZE], *tmp2, tmp3[64], tmp4[64];
  7549. StrToUni(tmp1, sizeof(tmp1), e->Name);
  7550. if (e->Active == false)
  7551. {
  7552. tmp2 = _UU("SM_L3_SW_ST_F_F");
  7553. }
  7554. else if (e->Online == false)
  7555. {
  7556. tmp2 = _UU("SM_L3_SW_ST_T_F");
  7557. }
  7558. else
  7559. {
  7560. tmp2 = _UU("SM_L3_SW_ST_T_T");
  7561. }
  7562. UniToStru(tmp3, e->NumInterfaces);
  7563. UniToStru(tmp4, e->NumTables);
  7564. CtInsert(ct,
  7565. tmp1, tmp2, tmp3, tmp4);
  7566. }
  7567. CtFree(ct, c);
  7568. }
  7569. FreeRpcEnumL3Sw(&t);
  7570. FreeParamValueList(o);
  7571. return 0;
  7572. }
  7573. // Define a new virtual layer 3 switch
  7574. UINT PsRouterAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7575. {
  7576. LIST *o;
  7577. PS *ps = (PS *)param;
  7578. UINT ret = 0;
  7579. RPC_L3SW t;
  7580. // Parameter list that can be specified
  7581. PARAM args[] =
  7582. {
  7583. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  7584. {"[name]", CmdPrompt, _UU("CMD_RouterAdd_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  7585. };
  7586. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7587. if (o == NULL)
  7588. {
  7589. return ERR_INVALID_PARAMETER;
  7590. }
  7591. Zero(&t, sizeof(t));
  7592. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  7593. // RPC call
  7594. ret = ScAddL3Switch(ps->Rpc, &t);
  7595. if (ret != ERR_NO_ERROR)
  7596. {
  7597. // An error has occured
  7598. CmdPrintError(c, ret);
  7599. FreeParamValueList(o);
  7600. return ret;
  7601. }
  7602. FreeParamValueList(o);
  7603. return 0;
  7604. }
  7605. // Delete the Virtual Layer 3 Switch
  7606. UINT PsRouterDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7607. {
  7608. LIST *o;
  7609. PS *ps = (PS *)param;
  7610. UINT ret = 0;
  7611. RPC_L3SW t;
  7612. // Parameter list that can be specified
  7613. PARAM args[] =
  7614. {
  7615. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  7616. {"[name]", CmdPrompt, _UU("CMD_RouterDelete_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  7617. };
  7618. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7619. if (o == NULL)
  7620. {
  7621. return ERR_INVALID_PARAMETER;
  7622. }
  7623. Zero(&t, sizeof(t));
  7624. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  7625. // RPC call
  7626. ret = ScDelL3Switch(ps->Rpc, &t);
  7627. if (ret != ERR_NO_ERROR)
  7628. {
  7629. // An error has occured
  7630. CmdPrintError(c, ret);
  7631. FreeParamValueList(o);
  7632. return ret;
  7633. }
  7634. FreeParamValueList(o);
  7635. return 0;
  7636. }
  7637. // Start the Virtual Layer 3 Switch
  7638. UINT PsRouterStart(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7639. {
  7640. LIST *o;
  7641. PS *ps = (PS *)param;
  7642. UINT ret = 0;
  7643. RPC_L3SW t;
  7644. // Parameter list that can be specified
  7645. PARAM args[] =
  7646. {
  7647. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  7648. {"[name]", CmdPrompt, _UU("CMD_RouterStart_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  7649. };
  7650. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7651. if (o == NULL)
  7652. {
  7653. return ERR_INVALID_PARAMETER;
  7654. }
  7655. Zero(&t, sizeof(t));
  7656. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  7657. // RPC call
  7658. ret = ScStartL3Switch(ps->Rpc, &t);
  7659. if (ret != ERR_NO_ERROR)
  7660. {
  7661. // An error has occured
  7662. CmdPrintError(c, ret);
  7663. FreeParamValueList(o);
  7664. return ret;
  7665. }
  7666. FreeParamValueList(o);
  7667. return 0;
  7668. }
  7669. // Stop the Virtual Layer 3 Switch
  7670. UINT PsRouterStop(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7671. {
  7672. LIST *o;
  7673. PS *ps = (PS *)param;
  7674. UINT ret = 0;
  7675. RPC_L3SW t;
  7676. // Parameter list that can be specified
  7677. PARAM args[] =
  7678. {
  7679. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  7680. {"[name]", CmdPrompt, _UU("CMD_RouterStop_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  7681. };
  7682. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7683. if (o == NULL)
  7684. {
  7685. return ERR_INVALID_PARAMETER;
  7686. }
  7687. Zero(&t, sizeof(t));
  7688. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  7689. // RPC call
  7690. ret = ScStopL3Switch(ps->Rpc, &t);
  7691. if (ret != ERR_NO_ERROR)
  7692. {
  7693. // An error has occured
  7694. CmdPrintError(c, ret);
  7695. FreeParamValueList(o);
  7696. return ret;
  7697. }
  7698. FreeParamValueList(o);
  7699. return 0;
  7700. }
  7701. // Get the interface list registered on Virtual Layer 3 Switch
  7702. UINT PsRouterIfList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7703. {
  7704. LIST *o;
  7705. PS *ps = (PS *)param;
  7706. UINT ret = 0;
  7707. RPC_ENUM_L3IF t;
  7708. // Parameter list that can be specified
  7709. PARAM args[] =
  7710. {
  7711. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  7712. {"[name]", CmdPrompt, _UU("CMD_RouterIfList_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  7713. };
  7714. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7715. if (o == NULL)
  7716. {
  7717. return ERR_INVALID_PARAMETER;
  7718. }
  7719. Zero(&t, sizeof(t));
  7720. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  7721. // RPC call
  7722. ret = ScEnumL3If(ps->Rpc, &t);
  7723. if (ret != ERR_NO_ERROR)
  7724. {
  7725. // An error has occured
  7726. CmdPrintError(c, ret);
  7727. FreeParamValueList(o);
  7728. return ret;
  7729. }
  7730. else
  7731. {
  7732. UINT i;
  7733. wchar_t tmp1[MAX_SIZE];
  7734. wchar_t tmp2[MAX_SIZE];
  7735. wchar_t tmp3[MAX_SIZE];
  7736. CT *ct = CtNew();
  7737. CtInsertColumn(ct, _UU("SM_L3_SW_IF_COLUMN1"), false);
  7738. CtInsertColumn(ct, _UU("SM_L3_SW_IF_COLUMN2"), false);
  7739. CtInsertColumn(ct, _UU("SM_L3_SW_IF_COLUMN3"), false);
  7740. for (i = 0;i < t.NumItem;i++)
  7741. {
  7742. RPC_L3IF *e = &t.Items[i];
  7743. IPToUniStr32(tmp1, sizeof(tmp1), e->IpAddress);
  7744. IPToUniStr32(tmp2, sizeof(tmp2), e->SubnetMask);
  7745. StrToUni(tmp3, sizeof(tmp3), e->HubName);
  7746. CtInsert(ct, tmp1, tmp2, tmp3);
  7747. }
  7748. CtFree(ct, c);
  7749. }
  7750. FreeRpcEnumL3If(&t);
  7751. FreeParamValueList(o);
  7752. return 0;
  7753. }
  7754. // Evaluate the IP address and mask
  7755. bool CmdEvalIpAndMask4(CONSOLE *c, wchar_t *str, void *param)
  7756. {
  7757. char tmp[MAX_SIZE];
  7758. UINT ip, mask;
  7759. // Validate arguments
  7760. if (c == NULL || str == NULL)
  7761. {
  7762. return false;
  7763. }
  7764. UniToStr(tmp, sizeof(tmp), str);
  7765. if (ParseIpAndMask4(tmp, &ip, &mask) == false)
  7766. {
  7767. c->Write(c, _UU("CMD_PARSE_IP_MASK_ERROR_1"));
  7768. return false;
  7769. }
  7770. return true;
  7771. }
  7772. bool CmdEvalIpAndMask6(CONSOLE *c, wchar_t *str, void *param)
  7773. {
  7774. char tmp[MAX_SIZE];
  7775. IP ip, mask;
  7776. // Validate arguments
  7777. if (c == NULL || str == NULL)
  7778. {
  7779. return false;
  7780. }
  7781. UniToStr(tmp, sizeof(tmp), str);
  7782. if (ParseIpAndMask6(tmp, &ip, &mask) == false)
  7783. {
  7784. c->Write(c, _UU("CMD_PARSE_IP_MASK_ERROR_1_6"));
  7785. return false;
  7786. }
  7787. return true;
  7788. }
  7789. bool CmdEvalIpAndMask46(CONSOLE *c, wchar_t *str, void *param)
  7790. {
  7791. char tmp[MAX_SIZE];
  7792. TOKEN_LIST *t;
  7793. bool ret = false;
  7794. Zero(tmp, sizeof(tmp));
  7795. UniToStr(tmp, sizeof(tmp), str);
  7796. t = ParseToken(tmp, "/");
  7797. if (t == NULL)
  7798. {
  7799. return false;
  7800. }
  7801. if (t->NumTokens >= 1)
  7802. {
  7803. Trim(t->Token[0]);
  7804. if (IsIpStr4(t->Token[0]))
  7805. {
  7806. ret = CmdEvalIpAndMask4(c, str, param);
  7807. }
  7808. else
  7809. {
  7810. ret = CmdEvalIpAndMask6(c, str, param);
  7811. }
  7812. }
  7813. FreeToken(t);
  7814. return ret;
  7815. }
  7816. // Evaluate the network address and the subnet mask
  7817. bool CmdEvalNetworkAndSubnetMask4(CONSOLE *c, wchar_t *str, void *param)
  7818. {
  7819. char tmp[MAX_SIZE];
  7820. UINT ip, mask;
  7821. // Validate arguments
  7822. if (c == NULL || str == NULL)
  7823. {
  7824. return false;
  7825. }
  7826. UniToStr(tmp, sizeof(tmp), str);
  7827. if (ParseIpAndSubnetMask4(tmp, &ip, &mask) == false)
  7828. {
  7829. c->Write(c, _UU("CMD_PARSE_IP_SUBNET_ERROR_1"));
  7830. return false;
  7831. }
  7832. if (IsNetworkAddress32(ip, mask) == false)
  7833. {
  7834. c->Write(c, _UU("CMD_PARSE_IP_SUBNET_ERROR_2"));
  7835. return false;
  7836. }
  7837. return true;
  7838. }
  7839. bool CmdEvalNetworkAndSubnetMask6(CONSOLE *c, wchar_t *str, void *param)
  7840. {
  7841. char tmp[MAX_SIZE];
  7842. IP ip, mask;
  7843. // Validate arguments
  7844. if (c == NULL || str == NULL)
  7845. {
  7846. return false;
  7847. }
  7848. UniToStr(tmp, sizeof(tmp), str);
  7849. if (ParseIpAndSubnetMask6(tmp, &ip, &mask) == false)
  7850. {
  7851. c->Write(c, _UU("CMD_PARSE_IP_SUBNET_ERROR_1_6"));
  7852. return false;
  7853. }
  7854. if (IsNetworkPrefixAddress6(&ip, &mask) == false)
  7855. {
  7856. c->Write(c, _UU("CMD_PARSE_IP_SUBNET_ERROR_3"));
  7857. return false;
  7858. }
  7859. return true;
  7860. }
  7861. bool CmdEvalNetworkAndSubnetMask46(CONSOLE *c, wchar_t *str, void *param)
  7862. {
  7863. char tmp[MAX_SIZE];
  7864. TOKEN_LIST *t;
  7865. bool ret = false;
  7866. Zero(tmp, sizeof(tmp));
  7867. UniToStr(tmp, sizeof(tmp), str);
  7868. t = ParseToken(tmp, "/");
  7869. if (t == NULL)
  7870. {
  7871. return false;
  7872. }
  7873. if (t->NumTokens >= 1)
  7874. {
  7875. Trim(t->Token[0]);
  7876. if (IsIpStr4(t->Token[0]))
  7877. {
  7878. ret = CmdEvalNetworkAndSubnetMask4(c, str, param);
  7879. }
  7880. else
  7881. {
  7882. ret = CmdEvalNetworkAndSubnetMask6(c, str, param);
  7883. }
  7884. }
  7885. FreeToken(t);
  7886. return ret;
  7887. }
  7888. // Evaluate the IP address and subnet mask
  7889. bool CmdEvalHostAndSubnetMask4(CONSOLE *c, wchar_t *str, void *param)
  7890. {
  7891. char tmp[MAX_SIZE];
  7892. // Validate arguments
  7893. if (c == NULL || str == NULL)
  7894. {
  7895. return false;
  7896. }
  7897. UniToStr(tmp, sizeof(tmp), str);
  7898. if (ParseIpAndSubnetMask4(tmp, NULL, NULL) == false)
  7899. {
  7900. c->Write(c, _UU("CMD_PARSE_IP_SUBNET_ERROR_1"));
  7901. return false;
  7902. }
  7903. return true;
  7904. }
  7905. // Add a virtual interface to the virtual layer 3 switch
  7906. UINT PsRouterIfAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7907. {
  7908. LIST *o;
  7909. PS *ps = (PS *)param;
  7910. UINT ret = 0;
  7911. RPC_L3IF t;
  7912. // Parameter list that can be specified
  7913. PARAM args[] =
  7914. {
  7915. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  7916. {"[name]", CmdPrompt, _UU("CMD_RouterIfAdd_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  7917. {"HUB", CmdPrompt, _UU("CMD_RouterIfAdd_PROMPT_HUB"), CmdEvalNotEmpty, NULL},
  7918. {"IP", CmdPrompt, _UU("CMD_RouterIfAdd_PROMPT_IP"), CmdEvalHostAndSubnetMask4, NULL},
  7919. };
  7920. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7921. if (o == NULL)
  7922. {
  7923. return ERR_INVALID_PARAMETER;
  7924. }
  7925. Zero(&t, sizeof(t));
  7926. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  7927. ParseIpAndSubnetMask4(GetParamStr(o, "IP"), &t.IpAddress, &t.SubnetMask);
  7928. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "HUB"));
  7929. // RPC call
  7930. ret = ScAddL3If(ps->Rpc, &t);
  7931. if (ret != ERR_NO_ERROR)
  7932. {
  7933. // An error has occured
  7934. CmdPrintError(c, ret);
  7935. FreeParamValueList(o);
  7936. return ret;
  7937. }
  7938. FreeParamValueList(o);
  7939. return 0;
  7940. }
  7941. // Delete the virtual interface of the virtual layer 3 switch
  7942. UINT PsRouterIfDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7943. {
  7944. LIST *o;
  7945. PS *ps = (PS *)param;
  7946. UINT ret = 0;
  7947. RPC_L3IF t;
  7948. // Parameter list that can be specified
  7949. PARAM args[] =
  7950. {
  7951. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  7952. {"[name]", CmdPrompt, _UU("CMD_RouterIfAdd_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  7953. {"HUB", CmdPrompt, _UU("CMD_RouterIfAdd_PROMPT_HUB"), CmdEvalNotEmpty, NULL},
  7954. };
  7955. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7956. if (o == NULL)
  7957. {
  7958. return ERR_INVALID_PARAMETER;
  7959. }
  7960. Zero(&t, sizeof(t));
  7961. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  7962. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "HUB"));
  7963. // RPC call
  7964. ret = ScDelL3If(ps->Rpc, &t);
  7965. if (ret != ERR_NO_ERROR)
  7966. {
  7967. // An error has occured
  7968. CmdPrintError(c, ret);
  7969. FreeParamValueList(o);
  7970. return ret;
  7971. }
  7972. FreeParamValueList(o);
  7973. return 0;
  7974. }
  7975. // Get the routing table of the Virtual Layer 3 Switch
  7976. UINT PsRouterTableList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  7977. {
  7978. LIST *o;
  7979. PS *ps = (PS *)param;
  7980. UINT ret = 0;
  7981. RPC_ENUM_L3TABLE t;
  7982. CT *ct;
  7983. wchar_t tmp1[MAX_SIZE];
  7984. wchar_t tmp2[MAX_SIZE];
  7985. wchar_t tmp3[MAX_SIZE];
  7986. wchar_t tmp4[MAX_SIZE];
  7987. // Parameter list that can be specified
  7988. PARAM args[] =
  7989. {
  7990. {"[name]", CmdPrompt, _UU("CMD_RouterTableList_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  7991. };
  7992. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  7993. if (o == NULL)
  7994. {
  7995. return ERR_INVALID_PARAMETER;
  7996. }
  7997. Zero(&t, sizeof(t));
  7998. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  7999. // RPC call
  8000. ret = ScEnumL3Table(ps->Rpc, &t);
  8001. if (ret != ERR_NO_ERROR)
  8002. {
  8003. // An error has occured
  8004. CmdPrintError(c, ret);
  8005. FreeParamValueList(o);
  8006. return ret;
  8007. }
  8008. else
  8009. {
  8010. UINT i;
  8011. ct = CtNew();
  8012. CtInsertColumn(ct, _UU("SM_L3_SW_TABLE_COLUMN1"), false);
  8013. CtInsertColumn(ct, _UU("SM_L3_SW_TABLE_COLUMN2"), false);
  8014. CtInsertColumn(ct, _UU("SM_L3_SW_TABLE_COLUMN3"), false);
  8015. CtInsertColumn(ct, _UU("SM_L3_SW_TABLE_COLUMN4"), true);
  8016. for (i = 0;i < t.NumItem;i++)
  8017. {
  8018. RPC_L3TABLE *e = &t.Items[i];
  8019. IPToUniStr32(tmp1, sizeof(tmp1), e->NetworkAddress);
  8020. IPToUniStr32(tmp2, sizeof(tmp2), e->SubnetMask);
  8021. IPToUniStr32(tmp3, sizeof(tmp3), e->GatewayAddress);
  8022. UniToStru(tmp4, e->Metric);
  8023. CtInsert(ct, tmp1, tmp2, tmp3, tmp4);
  8024. }
  8025. CtFree(ct, c);
  8026. }
  8027. FreeRpcEnumL3Table(&t);
  8028. FreeParamValueList(o);
  8029. return 0;
  8030. }
  8031. // Add a routing table entry to the Virtual Layer 3 Switch
  8032. UINT PsRouterTableAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8033. {
  8034. LIST *o;
  8035. PS *ps = (PS *)param;
  8036. UINT ret = 0;
  8037. RPC_L3TABLE t;
  8038. // Parameter list that can be specified
  8039. PARAM args[] =
  8040. {
  8041. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  8042. {"[name]", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  8043. {"NETWORK", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_NETWORK"), CmdEvalNetworkAndSubnetMask4, NULL},
  8044. {"GATEWAY", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_GATEWAY"), CmdEvalIp, NULL},
  8045. {"METRIC", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_METRIC"), CmdEvalInt1, NULL},
  8046. };
  8047. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8048. if (o == NULL)
  8049. {
  8050. return ERR_INVALID_PARAMETER;
  8051. }
  8052. Zero(&t, sizeof(t));
  8053. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  8054. ParseIpAndSubnetMask4(GetParamStr(o, "NETWORK"), &t.NetworkAddress, &t.SubnetMask);
  8055. t.Metric = GetParamInt(o, "METRIC");
  8056. t.GatewayAddress = StrToIP32(GetParamStr(o, "GATEWAY"));
  8057. // RPC call
  8058. ret = ScAddL3Table(ps->Rpc, &t);
  8059. if (ret != ERR_NO_ERROR)
  8060. {
  8061. // An error has occured
  8062. CmdPrintError(c, ret);
  8063. FreeParamValueList(o);
  8064. return ret;
  8065. }
  8066. FreeParamValueList(o);
  8067. return 0;
  8068. }
  8069. // Delete the routing table entry of the Virtual Layer 3 Switch
  8070. UINT PsRouterTableDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8071. {
  8072. LIST *o;
  8073. PS *ps = (PS *)param;
  8074. UINT ret = 0;
  8075. RPC_L3TABLE t;
  8076. // Parameter list that can be specified
  8077. PARAM args[] =
  8078. {
  8079. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  8080. {"[name]", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  8081. {"NETWORK", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_NETWORK"), CmdEvalNetworkAndSubnetMask4, NULL},
  8082. {"GATEWAY", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_GATEWAY"), CmdEvalIp, NULL},
  8083. {"METRIC", CmdPrompt, _UU("CMD_RouterTableAdd_PROMPT_METRIC"), CmdEvalInt1, NULL},
  8084. };
  8085. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8086. if (o == NULL)
  8087. {
  8088. return ERR_INVALID_PARAMETER;
  8089. }
  8090. Zero(&t, sizeof(t));
  8091. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  8092. ParseIpAndSubnetMask4(GetParamStr(o, "NETWORK"), &t.NetworkAddress, &t.SubnetMask);
  8093. t.Metric = GetParamInt(o, "METRIC");
  8094. t.GatewayAddress = StrToIP32(GetParamStr(o, "GATEWAY"));
  8095. // RPC call
  8096. ret = ScDelL3Table(ps->Rpc, &t);
  8097. if (ret != ERR_NO_ERROR)
  8098. {
  8099. // An error has occured
  8100. CmdPrintError(c, ret);
  8101. FreeParamValueList(o);
  8102. return ret;
  8103. }
  8104. FreeParamValueList(o);
  8105. return 0;
  8106. }
  8107. // Get the log files list
  8108. UINT PsLogFileList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8109. {
  8110. LIST *o;
  8111. PS *ps = (PS *)param;
  8112. UINT ret = 0;
  8113. RPC_ENUM_LOG_FILE t;
  8114. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  8115. if (o == NULL)
  8116. {
  8117. return ERR_INVALID_PARAMETER;
  8118. }
  8119. Zero(&t, sizeof(t));
  8120. c->Write(c, _UU("CMD_LogFileList_START"));
  8121. c->Write(c, L"");
  8122. // RPC call
  8123. ret = ScEnumLogFile(ps->Rpc, &t);
  8124. if (ret != ERR_NO_ERROR)
  8125. {
  8126. // An error has occured
  8127. CmdPrintError(c, ret);
  8128. FreeParamValueList(o);
  8129. return ret;
  8130. }
  8131. else
  8132. {
  8133. UINT i;
  8134. wchar_t tmp[MAX_SIZE];
  8135. CT *ct;
  8136. UniFormat(tmp, sizeof(tmp), _UU("CMD_LogFileList_NUM_LOGS"), t.NumItem);
  8137. c->Write(c, tmp);
  8138. ct = CtNew();
  8139. CtInsertColumn(ct, _UU("SM_LOG_FILE_COLUMN_1"), false);
  8140. CtInsertColumn(ct, _UU("SM_LOG_FILE_COLUMN_2"), true);
  8141. CtInsertColumn(ct, _UU("SM_LOG_FILE_COLUMN_3"), false);
  8142. CtInsertColumn(ct, _UU("SM_LOG_FILE_COLUMN_4"), false);
  8143. for (i = 0;i < t.NumItem;i++)
  8144. {
  8145. RPC_ENUM_LOG_FILE_ITEM *e = &t.Items[i];
  8146. wchar_t tmp1[MAX_PATH], tmp2[128], tmp3[128], tmp4[MAX_HOST_NAME_LEN + 1];
  8147. char tmp[MAX_SIZE];
  8148. StrToUni(tmp1, sizeof(tmp1), e->FilePath);
  8149. ToStrByte(tmp, sizeof(tmp), e->FileSize);
  8150. StrToUni(tmp2, sizeof(tmp2), tmp);
  8151. GetDateTimeStr64Uni(tmp3, sizeof(tmp3), SystemToLocal64(e->UpdatedTime));
  8152. StrToUni(tmp4, sizeof(tmp4), e->ServerName);
  8153. CtInsert(ct, tmp1, tmp2, tmp3, tmp4);
  8154. }
  8155. CtFreeEx(ct, c, true);
  8156. }
  8157. FreeRpcEnumLogFile(&t);
  8158. FreeParamValueList(o);
  8159. return 0;
  8160. }
  8161. // Download a log file
  8162. UINT PsLogFileGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8163. {
  8164. LIST *o;
  8165. PS *ps = (PS *)param;
  8166. UINT ret = 0;
  8167. BUF *buf;
  8168. char *filename = NULL;
  8169. char *server_name;
  8170. // Parameter list that can be specified
  8171. PARAM args[] =
  8172. {
  8173. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  8174. {"[name]", CmdPrompt, _UU("CMD_LogFileGet_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  8175. {"SERVER", NULL, NULL, NULL, NULL},
  8176. {"SAVEPATH", NULL, NULL, NULL, NULL},
  8177. };
  8178. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8179. if (o == NULL)
  8180. {
  8181. return ERR_INVALID_PARAMETER;
  8182. }
  8183. filename = GetParamStr(o, "SAVE");
  8184. c->Write(c, _UU("CMD_LogFileGet_START"));
  8185. server_name = GetParamStr(o, "SERVER");
  8186. buf = DownloadFileFromServer(ps->Rpc, server_name,
  8187. GetParamStr(o, "[name]"), 0, NULL, NULL);
  8188. if (buf == NULL)
  8189. {
  8190. c->Write(c, _UU("CMD_LogFileGet_FAILED"));
  8191. ret = ERR_INTERNAL_ERROR;
  8192. }
  8193. else
  8194. {
  8195. if (IsEmptyStr(filename) == false)
  8196. {
  8197. // Save to the file
  8198. if (DumpBuf(buf, filename) == false)
  8199. {
  8200. ret = ERR_INTERNAL_ERROR;
  8201. c->Write(c, _UU("CMD_LogFileGet_SAVE_FAILED"));
  8202. }
  8203. }
  8204. else
  8205. {
  8206. // Display on the screen
  8207. wchar_t tmp[MAX_SIZE];
  8208. UINT buf_size;
  8209. wchar_t *uni_buf;
  8210. UniFormat(tmp, sizeof(tmp), _UU("CMD_LogFileGet_FILESIZE"),
  8211. buf->Size);
  8212. c->Write(c, tmp);
  8213. c->Write(c, L"");
  8214. buf_size = CalcUtf8ToUni((BYTE *)buf->Buf, buf->Size);
  8215. uni_buf = ZeroMalloc(buf_size + 32);
  8216. Utf8ToUni(uni_buf, buf_size, (BYTE *)buf->Buf, buf->Size);
  8217. c->Write(c, uni_buf);
  8218. c->Write(c, L"");
  8219. Free(uni_buf);
  8220. }
  8221. FreeBuf(buf);
  8222. }
  8223. FreeParamValueList(o);
  8224. return ret;
  8225. }
  8226. // Create a New Virtual HUB
  8227. UINT PsHubCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8228. {
  8229. LIST *o;
  8230. PS *ps = (PS *)param;
  8231. UINT ret = 0;
  8232. RPC_CREATE_HUB t;
  8233. char *pass = "";
  8234. UINT hub_type = HUB_TYPE_STANDALONE;
  8235. // Parameter list that can be specified
  8236. PARAM args[] =
  8237. {
  8238. {"[name]", CmdPrompt, _UU("CMD_HubCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  8239. {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},
  8240. };
  8241. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8242. if (o == NULL)
  8243. {
  8244. return ERR_INVALID_PARAMETER;
  8245. }
  8246. else
  8247. {
  8248. RPC_SERVER_INFO t;
  8249. Zero(&t, sizeof(t));
  8250. if (ScGetServerInfo(ps->Rpc, &t) == ERR_NO_ERROR)
  8251. {
  8252. if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)
  8253. {
  8254. hub_type = HUB_TYPE_FARM_DYNAMIC;
  8255. }
  8256. FreeRpcServerInfo(&t);
  8257. }
  8258. }
  8259. Zero(&t, sizeof(t));
  8260. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));
  8261. t.HubType = hub_type;
  8262. if (IsEmptyStr(GetParamStr(o, "PASSWORD")) == false)
  8263. {
  8264. pass = GetParamStr(o, "PASSWORD");
  8265. }
  8266. Hash(t.HashedPassword, pass, StrLen(pass), true);
  8267. HashPassword(t.SecurePassword, ADMINISTRATOR_USERNAME, pass);
  8268. t.Online = true;
  8269. // RPC call
  8270. ret = ScCreateHub(ps->Rpc, &t);
  8271. if (ret != ERR_NO_ERROR)
  8272. {
  8273. // An error has occured
  8274. CmdPrintError(c, ret);
  8275. FreeParamValueList(o);
  8276. return ret;
  8277. }
  8278. FreeParamValueList(o);
  8279. return 0;
  8280. }
  8281. // Create a New Virtual HUB (dynamic mode)
  8282. UINT PsHubCreateDynamic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8283. {
  8284. LIST *o;
  8285. PS *ps = (PS *)param;
  8286. UINT ret = 0;
  8287. RPC_CREATE_HUB t;
  8288. char *pass = "";
  8289. UINT hub_type = HUB_TYPE_FARM_DYNAMIC;
  8290. // Parameter list that can be specified
  8291. PARAM args[] =
  8292. {
  8293. {"[name]", CmdPrompt, _UU("CMD_HubCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  8294. {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},
  8295. };
  8296. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8297. if (o == NULL)
  8298. {
  8299. return ERR_INVALID_PARAMETER;
  8300. }
  8301. Zero(&t, sizeof(t));
  8302. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));
  8303. t.HubType = hub_type;
  8304. if (IsEmptyStr(GetParamStr(o, "PASSWORD")) == false)
  8305. {
  8306. pass = GetParamStr(o, "PASSWORD");
  8307. }
  8308. Hash(t.HashedPassword, pass, StrLen(pass), true);
  8309. HashPassword(t.SecurePassword, ADMINISTRATOR_USERNAME, pass);
  8310. t.Online = true;
  8311. // RPC call
  8312. ret = ScCreateHub(ps->Rpc, &t);
  8313. if (ret != ERR_NO_ERROR)
  8314. {
  8315. // An error has occured
  8316. CmdPrintError(c, ret);
  8317. FreeParamValueList(o);
  8318. return ret;
  8319. }
  8320. FreeParamValueList(o);
  8321. return 0;
  8322. }
  8323. // Create a New Virtual HUB (static mode)
  8324. UINT PsHubCreateStatic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8325. {
  8326. LIST *o;
  8327. PS *ps = (PS *)param;
  8328. UINT ret = 0;
  8329. RPC_CREATE_HUB t;
  8330. char *pass = "";
  8331. UINT hub_type = HUB_TYPE_FARM_STATIC;
  8332. // Parameter list that can be specified
  8333. PARAM args[] =
  8334. {
  8335. {"[name]", CmdPrompt, _UU("CMD_HubCreate_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  8336. {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},
  8337. };
  8338. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8339. if (o == NULL)
  8340. {
  8341. return ERR_INVALID_PARAMETER;
  8342. }
  8343. Zero(&t, sizeof(t));
  8344. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));
  8345. t.HubType = hub_type;
  8346. if (IsEmptyStr(GetParamStr(o, "PASSWORD")) == false)
  8347. {
  8348. pass = GetParamStr(o, "PASSWORD");
  8349. }
  8350. Hash(t.HashedPassword, pass, StrLen(pass), true);
  8351. HashPassword(t.SecurePassword, ADMINISTRATOR_USERNAME, pass);
  8352. t.Online = true;
  8353. // RPC call
  8354. ret = ScCreateHub(ps->Rpc, &t);
  8355. if (ret != ERR_NO_ERROR)
  8356. {
  8357. // An error has occured
  8358. CmdPrintError(c, ret);
  8359. FreeParamValueList(o);
  8360. return ret;
  8361. }
  8362. FreeParamValueList(o);
  8363. return 0;
  8364. }
  8365. // Delete a Virtual HUB
  8366. UINT PsHubDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8367. {
  8368. LIST *o;
  8369. PS *ps = (PS *)param;
  8370. UINT ret = 0;
  8371. RPC_DELETE_HUB t;
  8372. // Parameter list that can be specified
  8373. PARAM args[] =
  8374. {
  8375. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  8376. {"[name]", CmdPrompt, _UU("CMD_HubDelete_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  8377. };
  8378. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8379. if (o == NULL)
  8380. {
  8381. return ERR_INVALID_PARAMETER;
  8382. }
  8383. Zero(&t, sizeof(t));
  8384. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));
  8385. // RPC call
  8386. ret = ScDeleteHub(ps->Rpc, &t);
  8387. if (ret != ERR_NO_ERROR)
  8388. {
  8389. // An error has occured
  8390. CmdPrintError(c, ret);
  8391. FreeParamValueList(o);
  8392. return ret;
  8393. }
  8394. FreeParamValueList(o);
  8395. return 0;
  8396. }
  8397. // Set the Virtual HUB to static
  8398. UINT PsHubSetStatic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8399. {
  8400. LIST *o;
  8401. PS *ps = (PS *)param;
  8402. UINT ret = 0;
  8403. RPC_CREATE_HUB t;
  8404. // Parameter list that can be specified
  8405. PARAM args[] =
  8406. {
  8407. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  8408. {"[name]", CmdPrompt, _UU("CMD_HubChange_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  8409. };
  8410. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8411. if (o == NULL)
  8412. {
  8413. return ERR_INVALID_PARAMETER;
  8414. }
  8415. Zero(&t, sizeof(t));
  8416. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));
  8417. // Retrieve the current setting first
  8418. ret = ScGetHub(ps->Rpc, &t);
  8419. if (ret != ERR_NO_ERROR)
  8420. {
  8421. // An error has occured
  8422. CmdPrintError(c, ret);
  8423. FreeParamValueList(o);
  8424. return ret;
  8425. }
  8426. // Change the settings
  8427. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));
  8428. t.HubType = HUB_TYPE_FARM_STATIC;
  8429. // Write
  8430. ret = ScSetHub(ps->Rpc, &t);
  8431. if (ret != ERR_NO_ERROR)
  8432. {
  8433. // An error has occured
  8434. CmdPrintError(c, ret);
  8435. FreeParamValueList(o);
  8436. return ret;
  8437. }
  8438. FreeParamValueList(o);
  8439. return 0;
  8440. }
  8441. // Change the type of Virtual HUB to dynamic Virtual HUB
  8442. UINT PsHubSetDynamic(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8443. {
  8444. LIST *o;
  8445. PS *ps = (PS *)param;
  8446. UINT ret = 0;
  8447. RPC_CREATE_HUB t;
  8448. // Parameter list that can be specified
  8449. PARAM args[] =
  8450. {
  8451. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  8452. {"[name]", CmdPrompt, _UU("CMD_HubChange_PROMPT_NAME"), CmdEvalNotEmpty, NULL},
  8453. };
  8454. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8455. if (o == NULL)
  8456. {
  8457. return ERR_INVALID_PARAMETER;
  8458. }
  8459. Zero(&t, sizeof(t));
  8460. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));
  8461. // Retrieve the current setting first
  8462. ret = ScGetHub(ps->Rpc, &t);
  8463. if (ret != ERR_NO_ERROR)
  8464. {
  8465. // An error has occured
  8466. CmdPrintError(c, ret);
  8467. FreeParamValueList(o);
  8468. return ret;
  8469. }
  8470. // Change the settings
  8471. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));
  8472. t.HubType = HUB_TYPE_FARM_DYNAMIC;
  8473. // Write
  8474. ret = ScSetHub(ps->Rpc, &t);
  8475. if (ret != ERR_NO_ERROR)
  8476. {
  8477. // An error has occured
  8478. CmdPrintError(c, ret);
  8479. FreeParamValueList(o);
  8480. return ret;
  8481. }
  8482. FreeParamValueList(o);
  8483. return 0;
  8484. }
  8485. // Get the list of Virtual HUB
  8486. UINT PsHubList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8487. {
  8488. LIST *o;
  8489. PS *ps = (PS *)param;
  8490. UINT ret = 0;
  8491. RPC_ENUM_HUB t;
  8492. UINT i;
  8493. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  8494. if (o == NULL)
  8495. {
  8496. return ERR_INVALID_PARAMETER;
  8497. }
  8498. Zero(&t, sizeof(t));
  8499. // RPC call
  8500. ret = ScEnumHub(ps->Rpc, &t);
  8501. if (ret != ERR_NO_ERROR)
  8502. {
  8503. // An error has occured
  8504. CmdPrintError(c, ret);
  8505. FreeParamValueList(o);
  8506. return ret;
  8507. }
  8508. else
  8509. {
  8510. CT *ct = CtNew();
  8511. CtInsertColumn(ct, _UU("SM_HUB_COLUMN_1"), false);
  8512. CtInsertColumn(ct, _UU("SM_HUB_COLUMN_2"), false);
  8513. CtInsertColumn(ct, _UU("SM_HUB_COLUMN_3"), false);
  8514. CtInsertColumn(ct, _UU("SM_HUB_COLUMN_4"), false);
  8515. CtInsertColumn(ct, _UU("SM_HUB_COLUMN_5"), false);
  8516. CtInsertColumn(ct, _UU("SM_HUB_COLUMN_6"), false);
  8517. CtInsertColumn(ct, _UU("SM_HUB_COLUMN_7"), false);
  8518. CtInsertColumn(ct, _UU("SM_HUB_COLUMN_8"), false);
  8519. CtInsertColumn(ct, _UU("SM_HUB_COLUMN_9"), false);
  8520. CtInsertColumn(ct, _UU("SM_HUB_COLUMN_10"), false);
  8521. CtInsertColumn(ct, _UU("SM_HUB_COLUMN_11"), false);
  8522. CtInsertColumn(ct, _UU("SM_SESS_COLUMN_6"), false);
  8523. CtInsertColumn(ct, _UU("SM_SESS_COLUMN_7"), false);
  8524. for (i = 0;i < t.NumHub;i++)
  8525. {
  8526. RPC_ENUM_HUB_ITEM *e = &t.Hubs[i];
  8527. wchar_t name[MAX_HUBNAME_LEN + 1];
  8528. wchar_t s1[64], s2[64], s3[64], s4[64], s5[64];
  8529. wchar_t s6[64], s7[128], s8[128];
  8530. wchar_t s9[64], s10[64];
  8531. UniToStru(s1, e->NumUsers);
  8532. UniToStru(s2, e->NumGroups);
  8533. UniToStru(s3, e->NumSessions);
  8534. UniToStru(s4, e->NumMacTables);
  8535. UniToStru(s5, e->NumIpTables);
  8536. UniToStru(s6, e->NumLogin);
  8537. if (e->LastLoginTime != 0)
  8538. {
  8539. GetDateTimeStr64Uni(s7, sizeof(s7), SystemToLocal64(e->LastLoginTime));
  8540. }
  8541. else
  8542. {
  8543. UniStrCpy(s7, sizeof(s7), _UU("COMMON_UNKNOWN"));
  8544. }
  8545. if (e->LastCommTime != 0)
  8546. {
  8547. GetDateTimeStr64Uni(s8, sizeof(s8), SystemToLocal64(e->LastCommTime));
  8548. }
  8549. else
  8550. {
  8551. UniStrCpy(s8, sizeof(s8), _UU("COMMON_UNKNOWN"));
  8552. }
  8553. if (e->IsTrafficFilled == false)
  8554. {
  8555. UniStrCpy(s9, sizeof(s9), _UU("CM_ST_NONE"));
  8556. UniStrCpy(s10, sizeof(s10), _UU("CM_ST_NONE"));
  8557. }
  8558. else
  8559. {
  8560. UniToStr3(s9, sizeof(s9),
  8561. e->Traffic.Recv.BroadcastBytes + e->Traffic.Recv.UnicastBytes +
  8562. e->Traffic.Send.BroadcastBytes + e->Traffic.Send.UnicastBytes);
  8563. UniToStr3(s10, sizeof(s10),
  8564. e->Traffic.Recv.BroadcastCount + e->Traffic.Recv.UnicastCount +
  8565. e->Traffic.Send.BroadcastCount + e->Traffic.Send.UnicastCount);
  8566. }
  8567. StrToUni(name, sizeof(name), e->HubName);
  8568. CtInsert(ct,
  8569. name,
  8570. e->Online ? _UU("SM_HUB_ONLINE") : _UU("SM_HUB_OFFLINE"),
  8571. GetHubTypeStr(e->HubType),
  8572. s1, s2, s3, s4, s5, s6, s7, s8, s9, s10);
  8573. }
  8574. CtFreeEx(ct, c, true);
  8575. }
  8576. FreeRpcEnumHub(&t);
  8577. FreeParamValueList(o);
  8578. return 0;
  8579. }
  8580. // Select a Virtual HUB to manage
  8581. UINT PsHub(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8582. {
  8583. LIST *o;
  8584. PS *ps = (PS *)param;
  8585. UINT ret = 0;
  8586. RPC_HUB_STATUS t;
  8587. // Parameter list that can be specified
  8588. PARAM args[] =
  8589. {
  8590. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  8591. {"[name]", NULL, NULL, NULL, NULL},
  8592. };
  8593. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8594. if (o == NULL)
  8595. {
  8596. return ERR_INVALID_PARAMETER;
  8597. }
  8598. if (IsEmptyStr(GetParamStr(o, "[name]")) == false)
  8599. {
  8600. wchar_t tmp[MAX_SIZE];
  8601. Zero(&t, sizeof(t));
  8602. // Examine whether the specified Virtual HUB is accessible
  8603. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "[name]"));
  8604. // RPC call
  8605. ret = ScGetHubStatus(ps->Rpc, &t);
  8606. if (ret != ERR_NO_ERROR)
  8607. {
  8608. // An error has occured
  8609. CmdPrintError(c, ret);
  8610. FreeParamValueList(o);
  8611. return ret;
  8612. }
  8613. // Change the selection
  8614. if (ps->HubName != NULL)
  8615. {
  8616. Free(ps->HubName);
  8617. }
  8618. ps->HubName = CopyStr(t.HubName);
  8619. UniFormat(tmp, sizeof(tmp), _UU("CMD_Hub_Selected"), t.HubName);
  8620. c->Write(c, tmp);
  8621. }
  8622. else
  8623. {
  8624. // Deselect
  8625. if (ps->HubName != NULL)
  8626. {
  8627. c->Write(c, _UU("CMD_Hub_Unselected"));
  8628. Free(ps->HubName);
  8629. }
  8630. ps->HubName = NULL;
  8631. }
  8632. FreeParamValueList(o);
  8633. return 0;
  8634. }
  8635. // Set the Virtual HUB to online
  8636. UINT PsOnline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8637. {
  8638. LIST *o;
  8639. PS *ps = (PS *)param;
  8640. UINT ret = 0;
  8641. RPC_SET_HUB_ONLINE t;
  8642. // If virtual HUB is not selected, it's an error
  8643. if (ps->HubName == NULL)
  8644. {
  8645. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  8646. return ERR_INVALID_PARAMETER;
  8647. }
  8648. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  8649. if (o == NULL)
  8650. {
  8651. return ERR_INVALID_PARAMETER;
  8652. }
  8653. Zero(&t, sizeof(t));
  8654. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  8655. t.Online = true;
  8656. // RPC call
  8657. ret = ScSetHubOnline(ps->Rpc, &t);
  8658. if (ret != ERR_NO_ERROR)
  8659. {
  8660. // An error has occured
  8661. CmdPrintError(c, ret);
  8662. FreeParamValueList(o);
  8663. return ret;
  8664. }
  8665. FreeParamValueList(o);
  8666. return 0;
  8667. }
  8668. // Set the Virtual HUB to offline
  8669. UINT PsOffline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8670. {
  8671. LIST *o;
  8672. PS *ps = (PS *)param;
  8673. UINT ret = 0;
  8674. RPC_SET_HUB_ONLINE t;
  8675. // If virtual HUB is not selected, it's an error
  8676. if (ps->HubName == NULL)
  8677. {
  8678. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  8679. return ERR_INVALID_PARAMETER;
  8680. }
  8681. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  8682. if (o == NULL)
  8683. {
  8684. return ERR_INVALID_PARAMETER;
  8685. }
  8686. Zero(&t, sizeof(t));
  8687. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  8688. t.Online = false;
  8689. // RPC call
  8690. ret = ScSetHubOnline(ps->Rpc, &t);
  8691. if (ret != ERR_NO_ERROR)
  8692. {
  8693. // An error has occured
  8694. CmdPrintError(c, ret);
  8695. FreeParamValueList(o);
  8696. return ret;
  8697. }
  8698. FreeParamValueList(o);
  8699. return 0;
  8700. }
  8701. // Set the maximum number of concurrent connecting sessions of the Virtual HUB
  8702. UINT PsSetMaxSession(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8703. {
  8704. LIST *o;
  8705. PS *ps = (PS *)param;
  8706. UINT ret = 0;
  8707. RPC_CREATE_HUB t;
  8708. // Parameter list that can be specified
  8709. PARAM args[] =
  8710. {
  8711. {"[max_session]", CmdPrompt, _UU("CMD_SetMaxSession_Prompt"), CmdEvalNotEmpty, NULL},
  8712. };
  8713. // If virtual HUB is not selected, it's an error
  8714. if (ps->HubName == NULL)
  8715. {
  8716. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  8717. return ERR_INVALID_PARAMETER;
  8718. }
  8719. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8720. if (o == NULL)
  8721. {
  8722. return ERR_INVALID_PARAMETER;
  8723. }
  8724. // Get current settings of Virtual HUB
  8725. Zero(&t, sizeof(t));
  8726. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  8727. ret = ScGetHub(ps->Rpc, &t);
  8728. if (ret != ERR_NO_ERROR)
  8729. {
  8730. // An error has occured
  8731. CmdPrintError(c, ret);
  8732. FreeParamValueList(o);
  8733. return ret;
  8734. }
  8735. t.HubOption.MaxSession = GetParamInt(o, "[max_session]");
  8736. // Write the configuration of Virtual HUB
  8737. ret = ScSetHub(ps->Rpc, &t);
  8738. if (ret != ERR_NO_ERROR)
  8739. {
  8740. // An error has occured
  8741. CmdPrintError(c, ret);
  8742. FreeParamValueList(o);
  8743. return ret;
  8744. }
  8745. FreeParamValueList(o);
  8746. return 0;
  8747. }
  8748. // Set the administrative password of the Virtual HUB
  8749. UINT PsSetHubPassword(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8750. {
  8751. LIST *o;
  8752. PS *ps = (PS *)param;
  8753. UINT ret = 0;
  8754. RPC_CREATE_HUB t;
  8755. char *pw;
  8756. // Parameter list that can be specified
  8757. PARAM args[] =
  8758. {
  8759. {"[password]", CmdPromptChoosePassword, NULL, NULL, NULL},
  8760. };
  8761. // If virtual HUB is not selected, it's an error
  8762. if (ps->HubName == NULL)
  8763. {
  8764. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  8765. return ERR_INVALID_PARAMETER;
  8766. }
  8767. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8768. if (o == NULL)
  8769. {
  8770. return ERR_INVALID_PARAMETER;
  8771. }
  8772. // Get current settings of Virtual HUB
  8773. Zero(&t, sizeof(t));
  8774. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  8775. ret = ScGetHub(ps->Rpc, &t);
  8776. if (ret != ERR_NO_ERROR)
  8777. {
  8778. // An error has occured
  8779. CmdPrintError(c, ret);
  8780. FreeParamValueList(o);
  8781. return ret;
  8782. }
  8783. // Change the settings
  8784. pw = GetParamStr(o, "[password]");
  8785. HashPassword(t.SecurePassword, ADMINISTRATOR_USERNAME, pw);
  8786. Hash(t.HashedPassword, pw, StrLen(pw), true);
  8787. // Write the configuration of Virtual HUB
  8788. ret = ScSetHub(ps->Rpc, &t);
  8789. if (ret != ERR_NO_ERROR)
  8790. {
  8791. // An error has occured
  8792. CmdPrintError(c, ret);
  8793. FreeParamValueList(o);
  8794. return ret;
  8795. }
  8796. FreeParamValueList(o);
  8797. return 0;
  8798. }
  8799. // Set the Virtual HUB to permit to be enumerated for anonymous users
  8800. UINT PsSetEnumAllow(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8801. {
  8802. LIST *o;
  8803. PS *ps = (PS *)param;
  8804. UINT ret = 0;
  8805. RPC_CREATE_HUB t;
  8806. // If virtual HUB is not selected, it's an error
  8807. if (ps->HubName == NULL)
  8808. {
  8809. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  8810. return ERR_INVALID_PARAMETER;
  8811. }
  8812. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  8813. if (o == NULL)
  8814. {
  8815. return ERR_INVALID_PARAMETER;
  8816. }
  8817. // Get current settings of Virtual HUB
  8818. Zero(&t, sizeof(t));
  8819. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  8820. ret = ScGetHub(ps->Rpc, &t);
  8821. if (ret != ERR_NO_ERROR)
  8822. {
  8823. // An error has occured
  8824. CmdPrintError(c, ret);
  8825. FreeParamValueList(o);
  8826. return ret;
  8827. }
  8828. t.HubOption.NoEnum = false;
  8829. // Write the configuration of Virtual HUB
  8830. ret = ScSetHub(ps->Rpc, &t);
  8831. if (ret != ERR_NO_ERROR)
  8832. {
  8833. // An error has occured
  8834. CmdPrintError(c, ret);
  8835. FreeParamValueList(o);
  8836. return ret;
  8837. }
  8838. FreeParamValueList(o);
  8839. return 0;
  8840. }
  8841. // Set the Virtual HUB to deny to be enumerated for anonymous users
  8842. UINT PsSetEnumDeny(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8843. {
  8844. LIST *o;
  8845. PS *ps = (PS *)param;
  8846. UINT ret = 0;
  8847. RPC_CREATE_HUB t;
  8848. // If virtual HUB is not selected, it's an error
  8849. if (ps->HubName == NULL)
  8850. {
  8851. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  8852. return ERR_INVALID_PARAMETER;
  8853. }
  8854. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  8855. if (o == NULL)
  8856. {
  8857. return ERR_INVALID_PARAMETER;
  8858. }
  8859. // Get current settings of Virtual HUB
  8860. Zero(&t, sizeof(t));
  8861. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  8862. ret = ScGetHub(ps->Rpc, &t);
  8863. if (ret != ERR_NO_ERROR)
  8864. {
  8865. // An error has occured
  8866. CmdPrintError(c, ret);
  8867. FreeParamValueList(o);
  8868. return ret;
  8869. }
  8870. t.HubOption.NoEnum = true;
  8871. // Write the configuration of Virtual HUB
  8872. ret = ScSetHub(ps->Rpc, &t);
  8873. if (ret != ERR_NO_ERROR)
  8874. {
  8875. // An error has occured
  8876. CmdPrintError(c, ret);
  8877. FreeParamValueList(o);
  8878. return ret;
  8879. }
  8880. FreeParamValueList(o);
  8881. return 0;
  8882. }
  8883. // Get the option settings for the virtual HUB
  8884. UINT PsOptionsGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8885. {
  8886. LIST *o;
  8887. PS *ps = (PS *)param;
  8888. UINT ret = 0;
  8889. RPC_CREATE_HUB t;
  8890. // If virtual HUB is not selected, it's an error
  8891. if (ps->HubName == NULL)
  8892. {
  8893. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  8894. return ERR_INVALID_PARAMETER;
  8895. }
  8896. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  8897. if (o == NULL)
  8898. {
  8899. return ERR_INVALID_PARAMETER;
  8900. }
  8901. Zero(&t, sizeof(t));
  8902. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  8903. // RPC call
  8904. ret = ScGetHub(ps->Rpc, &t);
  8905. if (ret != ERR_NO_ERROR)
  8906. {
  8907. // An error has occured
  8908. CmdPrintError(c, ret);
  8909. FreeParamValueList(o);
  8910. return ret;
  8911. }
  8912. else
  8913. {
  8914. CT *ct;
  8915. wchar_t tmp[MAX_SIZE];
  8916. UniFormat(tmp, sizeof(tmp), _UU("CMD_OptionsGet_TITLE"), ps->HubName);
  8917. c->Write(c, tmp);
  8918. // Display settings
  8919. ct = CtNewStandard();
  8920. CtInsert(ct, _UU("CMD_OptionsGet_ENUM"),
  8921. t.HubOption.NoEnum ? _UU("CMD_MSG_DENY") : _UU("CMD_MSG_ALLOW"));
  8922. if (t.HubOption.MaxSession == 0)
  8923. {
  8924. UniStrCpy(tmp, sizeof(tmp), _UU("CMD_MSG_INFINITE"));
  8925. }
  8926. else
  8927. {
  8928. UniToStru(tmp, t.HubOption.MaxSession);
  8929. }
  8930. CtInsert(ct, _UU("CMD_OptionsGet_MAXSESSIONS"), tmp);
  8931. CtInsert(ct, _UU("CMD_OptionsGet_STATUS"), t.Online ? _UU("SM_HUB_ONLINE") : _UU("SM_HUB_OFFLINE"));
  8932. CtInsert(ct, _UU("CMD_OptionsGet_TYPE"), GetHubTypeStr(t.HubType));
  8933. CtFree(ct, c);
  8934. }
  8935. FreeParamValueList(o);
  8936. return 0;
  8937. }
  8938. // Setting the Radius server to use for user authentication
  8939. UINT PsRadiusServerSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8940. {
  8941. LIST *o;
  8942. PS *ps = (PS *)param;
  8943. UINT ret = 0;
  8944. RPC_RADIUS t;
  8945. char *host;
  8946. UINT port;
  8947. // Parameter list that can be specified
  8948. CMD_EVAL_MIN_MAX minmax =
  8949. {
  8950. "CMD_RadiusServerSet_EVAL_NUMINTERVAL", RADIUS_RETRY_INTERVAL, RADIUS_RETRY_TIMEOUT,
  8951. };
  8952. PARAM args[] =
  8953. {
  8954. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  8955. {"[server_name:port]", CmdPrompt, _UU("CMD_RadiusServerSet_Prompt_Host"), CmdEvalNotEmpty, NULL},
  8956. {"SECRET", CmdPromptChoosePassword, _UU("CMD_RadiusServerSet_Prompt_Secret"), NULL, NULL},
  8957. {"RETRY_INTERVAL", CmdPrompt, _UU("CMD_RadiusServerSet_Prompt_RetryInterval"), CmdEvalMinMax, &minmax},
  8958. };
  8959. // If virtual HUB is not selected, it's an error
  8960. if (ps->HubName == NULL)
  8961. {
  8962. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  8963. return ERR_INVALID_PARAMETER;
  8964. }
  8965. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  8966. if (o == NULL)
  8967. {
  8968. return ERR_INVALID_PARAMETER;
  8969. }
  8970. if (ParseHostPort(GetParamStr(o, "[server_name:port]"), &host, &port, 1812))
  8971. {
  8972. Zero(&t, sizeof(t));
  8973. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  8974. t.RadiusPort = port;
  8975. StrCpy(t.RadiusServerName, sizeof(t.RadiusServerName), host);
  8976. StrCpy(t.RadiusSecret, sizeof(t.RadiusSecret), GetParamStr(o, "SECRET"));
  8977. t.RadiusRetryInterval = GetParamInt(o, "RETRY_INTERVAL");
  8978. Free(host);
  8979. // RPC call
  8980. ret = ScSetHubRadius(ps->Rpc, &t);
  8981. if (ret != ERR_NO_ERROR)
  8982. {
  8983. // An error has occured
  8984. CmdPrintError(c, ret);
  8985. FreeParamValueList(o);
  8986. return ret;
  8987. }
  8988. }
  8989. FreeParamValueList(o);
  8990. return 0;
  8991. }
  8992. // Delete the Radius server configuration to be used for user authentication
  8993. UINT PsRadiusServerDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  8994. {
  8995. LIST *o;
  8996. PS *ps = (PS *)param;
  8997. UINT ret = 0;
  8998. RPC_RADIUS t;
  8999. // If virtual HUB is not selected, it's an error
  9000. if (ps->HubName == NULL)
  9001. {
  9002. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9003. return ERR_INVALID_PARAMETER;
  9004. }
  9005. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  9006. if (o == NULL)
  9007. {
  9008. return ERR_INVALID_PARAMETER;
  9009. }
  9010. Zero(&t, sizeof(t));
  9011. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9012. t.RadiusPort = 1812;
  9013. // RPC call
  9014. ret = ScSetHubRadius(ps->Rpc, &t);
  9015. if (ret != ERR_NO_ERROR)
  9016. {
  9017. // An error has occured
  9018. CmdPrintError(c, ret);
  9019. FreeParamValueList(o);
  9020. return ret;
  9021. }
  9022. FreeParamValueList(o);
  9023. return 0;
  9024. }
  9025. // Get the Radius server settings to use for user authentication
  9026. UINT PsRadiusServerGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9027. {
  9028. LIST *o;
  9029. PS *ps = (PS *)param;
  9030. UINT ret = 0;
  9031. RPC_RADIUS t;
  9032. // If virtual HUB is not selected, it's an error
  9033. if (ps->HubName == NULL)
  9034. {
  9035. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9036. return ERR_INVALID_PARAMETER;
  9037. }
  9038. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  9039. if (o == NULL)
  9040. {
  9041. return ERR_INVALID_PARAMETER;
  9042. }
  9043. Zero(&t, sizeof(t));
  9044. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9045. // RPC call
  9046. ret = ScGetHubRadius(ps->Rpc, &t);
  9047. if (ret != ERR_NO_ERROR)
  9048. {
  9049. // An error has occured
  9050. CmdPrintError(c, ret);
  9051. FreeParamValueList(o);
  9052. return ret;
  9053. }
  9054. else
  9055. {
  9056. CT *ct;
  9057. wchar_t tmp[MAX_SIZE];
  9058. ct = CtNewStandard();
  9059. if (IsEmptyStr(t.RadiusServerName))
  9060. {
  9061. CtInsert(ct, _UU("CMD_RadiusServerGet_STATUS"), _UU("CMD_MSG_DISABLE"));
  9062. }
  9063. else
  9064. {
  9065. CtInsert(ct, _UU("CMD_RadiusServerGet_STATUS"), _UU("CMD_MSG_ENABLE"));
  9066. StrToUni(tmp, sizeof(tmp), t.RadiusServerName);
  9067. CtInsert(ct, _UU("CMD_RadiusServerGet_HOST"), tmp);
  9068. UniToStri(tmp, t.RadiusPort);
  9069. CtInsert(ct, _UU("CMD_RadiusServerGet_PORT"), tmp);
  9070. StrToUni(tmp, sizeof(tmp), t.RadiusSecret);
  9071. CtInsert(ct, _UU("CMD_RadiusServerGet_SECRET"), tmp);
  9072. UniToStri(tmp, t.RadiusRetryInterval);
  9073. CtInsert(ct, _UU("CMD_RadiusServerGet_RetryInterval"), tmp);
  9074. }
  9075. CtFree(ct, c);
  9076. }
  9077. FreeParamValueList(o);
  9078. return 0;
  9079. }
  9080. // Get the current status of the Virtual HUB
  9081. UINT PsStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9082. {
  9083. LIST *o;
  9084. PS *ps = (PS *)param;
  9085. UINT ret = 0;
  9086. RPC_HUB_STATUS t;
  9087. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  9088. if (o == NULL)
  9089. {
  9090. return ERR_INVALID_PARAMETER;
  9091. }
  9092. // If virtual HUB is not selected, it's an error
  9093. if (ps->HubName == NULL)
  9094. {
  9095. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9096. return ERR_INVALID_PARAMETER;
  9097. }
  9098. Zero(&t, sizeof(t));
  9099. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9100. // RPC call
  9101. ret = ScGetHubStatus(ps->Rpc, &t);
  9102. if (ret != ERR_NO_ERROR)
  9103. {
  9104. // An error has occured
  9105. CmdPrintError(c, ret);
  9106. FreeParamValueList(o);
  9107. return ret;
  9108. }
  9109. else
  9110. {
  9111. CT *ct = CtNewStandard();
  9112. wchar_t *s;
  9113. wchar_t tmp[MAX_SIZE];
  9114. // HUB name
  9115. s = CopyStrToUni(t.HubName);
  9116. CtInsert(ct, _UU("SM_HUB_STATUS_HUBNAME"), s);
  9117. Free(s);
  9118. // Online
  9119. CtInsert(ct, _UU("SM_HUB_STATUS_ONLINE"),
  9120. t.Online ? _UU("SM_HUB_ONLINE") : _UU("SM_HUB_OFFLINE"));
  9121. // Type of HUB
  9122. CtInsert(ct, _UU("SM_HUB_TYPE"),
  9123. GetHubTypeStr(t.HubType));
  9124. if (t.HubType == HUB_TYPE_STANDALONE)
  9125. {
  9126. // Enable / Disable the SecureNAT
  9127. CtInsert(ct, _UU("SM_HUB_SECURE_NAT"),
  9128. t.SecureNATEnabled ? _UU("SM_HUB_SECURE_NAT_YES") : _UU("SM_HUB_SECURE_NAT_NO"));
  9129. }
  9130. // Other values
  9131. UniToStru(tmp, t.NumSessions);
  9132. CtInsert(ct, _UU("SM_HUB_NUM_SESSIONS"), tmp);
  9133. if (t.NumSessionsClient != 0 || t.NumSessionsBridge != 0)
  9134. {
  9135. UniToStru(tmp, t.NumSessionsClient);
  9136. CtInsert(ct, _UU("SM_HUB_NUM_SESSIONS_CLIENT"), tmp);
  9137. UniToStru(tmp, t.NumSessionsBridge);
  9138. CtInsert(ct, _UU("SM_HUB_NUM_SESSIONS_BRIDGE"), tmp);
  9139. }
  9140. UniToStru(tmp, t.NumAccessLists);
  9141. CtInsert(ct, _UU("SM_HUB_NUM_ACCESSES"), tmp);
  9142. UniToStru(tmp, t.NumUsers);
  9143. CtInsert(ct, _UU("SM_HUB_NUM_USERS"), tmp);
  9144. UniToStru(tmp, t.NumGroups);
  9145. CtInsert(ct, _UU("SM_HUB_NUM_GROUPS"), tmp);
  9146. UniToStru(tmp, t.NumMacTables);
  9147. CtInsert(ct, _UU("SM_HUB_NUM_MAC_TABLES"), tmp);
  9148. UniToStru(tmp, t.NumIpTables);
  9149. CtInsert(ct, _UU("SM_HUB_NUM_IP_TABLES"), tmp);
  9150. // Usage status
  9151. UniToStru(tmp, t.NumLogin);
  9152. CtInsert(ct, _UU("SM_HUB_NUM_LOGIN"), tmp);
  9153. if (t.LastLoginTime != 0)
  9154. {
  9155. GetDateTimeStr64Uni(tmp, sizeof(tmp), SystemToLocal64(t.LastLoginTime));
  9156. }
  9157. else
  9158. {
  9159. UniStrCpy(tmp, sizeof(tmp), _UU("COMMON_UNKNOWN"));
  9160. }
  9161. CtInsert(ct, _UU("SM_HUB_LAST_LOGIN_TIME"), tmp);
  9162. if (t.LastCommTime != 0)
  9163. {
  9164. GetDateTimeStr64Uni(tmp, sizeof(tmp), SystemToLocal64(t.LastCommTime));
  9165. }
  9166. else
  9167. {
  9168. UniStrCpy(tmp, sizeof(tmp), _UU("COMMON_UNKNOWN"));
  9169. }
  9170. CtInsert(ct, _UU("SM_HUB_LAST_COMM_TIME"), tmp);
  9171. if (t.CreatedTime != 0)
  9172. {
  9173. GetDateTimeStr64Uni(tmp, sizeof(tmp), SystemToLocal64(t.CreatedTime));
  9174. }
  9175. else
  9176. {
  9177. UniStrCpy(tmp, sizeof(tmp), _UU("COMMON_UNKNOWN"));
  9178. }
  9179. CtInsert(ct, _UU("SM_HUB_CREATED_TIME"), tmp);
  9180. // Traffic information
  9181. CmdInsertTrafficInfo(ct, &t.Traffic);
  9182. CtFree(ct, c);
  9183. }
  9184. FreeParamValueList(o);
  9185. return 0;
  9186. }
  9187. // Get the log switching string
  9188. wchar_t *GetLogSwitchStr(UINT i)
  9189. {
  9190. char tmp[64];
  9191. Format(tmp, sizeof(tmp), "SM_LOG_SWITCH_%u", i);
  9192. return _UU(tmp);
  9193. }
  9194. // Get the packet log name string
  9195. wchar_t *GetPacketLogNameStr(UINT i)
  9196. {
  9197. char tmp[64];
  9198. Format(tmp, sizeof(tmp), "CMD_Log_%u", i);
  9199. return _UU(tmp);
  9200. }
  9201. // Get the log storage settings for the virtual HUB
  9202. UINT PsLogGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9203. {
  9204. LIST *o;
  9205. PS *ps = (PS *)param;
  9206. UINT ret = 0;
  9207. RPC_HUB_LOG t;
  9208. // If virtual HUB is not selected, it's an error
  9209. if (ps->HubName == NULL)
  9210. {
  9211. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9212. return ERR_INVALID_PARAMETER;
  9213. }
  9214. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  9215. if (o == NULL)
  9216. {
  9217. return ERR_INVALID_PARAMETER;
  9218. }
  9219. Zero(&t, sizeof(t));
  9220. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9221. // RPC call
  9222. ret = ScGetHubLog(ps->Rpc, &t);
  9223. if (ret != ERR_NO_ERROR)
  9224. {
  9225. // An error has occured
  9226. CmdPrintError(c, ret);
  9227. FreeParamValueList(o);
  9228. return ret;
  9229. }
  9230. else
  9231. {
  9232. CT *ct = CtNewStandard();
  9233. CtInsert(ct, _UU("CMD_Log_SecurityLog"),
  9234. t.LogSetting.SaveSecurityLog ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  9235. if (t.LogSetting.SaveSecurityLog)
  9236. {
  9237. CtInsert(ct, _UU("CMD_Log_SwitchType"), GetLogSwitchStr(t.LogSetting.SecurityLogSwitchType));
  9238. }
  9239. CtInsert(ct, L"", L"");
  9240. CtInsert(ct, _UU("CMD_Log_PacketLog"),
  9241. t.LogSetting.SavePacketLog ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  9242. if (t.LogSetting.SavePacketLog)
  9243. {
  9244. UINT i;
  9245. CtInsert(ct, _UU("CMD_Log_SwitchType"), GetLogSwitchStr(t.LogSetting.PacketLogSwitchType));
  9246. for (i = 0;i <= 7;i++)
  9247. {
  9248. wchar_t *tmp = NULL;
  9249. switch (t.LogSetting.PacketLogConfig[i])
  9250. {
  9251. case PACKET_LOG_NONE:
  9252. tmp = _UU("D_SM_LOG@B_PACKET_0_0");
  9253. break;
  9254. case PACKET_LOG_HEADER:
  9255. tmp = _UU("D_SM_LOG@B_PACKET_0_1");
  9256. break;
  9257. case PACKET_LOG_ALL:
  9258. tmp = _UU("D_SM_LOG@B_PACKET_0_2");
  9259. break;
  9260. }
  9261. CtInsert(ct, GetPacketLogNameStr(i),
  9262. tmp);
  9263. }
  9264. }
  9265. CtFree(ct, c);
  9266. }
  9267. FreeParamValueList(o);
  9268. return 0;
  9269. }
  9270. // LogEnable command
  9271. UINT PsLogEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9272. {
  9273. LIST *o;
  9274. PS *ps = (PS *)param;
  9275. UINT ret = 0;
  9276. RPC_HUB_LOG t;
  9277. bool packet_log = false;
  9278. char *tmp;
  9279. // Parameter list that can be specified
  9280. PARAM args[] =
  9281. {
  9282. {"[security|packet]", CmdPrompt, _UU("CMD_LogEnable_Prompt"), CmdEvalNotEmpty, NULL},
  9283. };
  9284. // If virtual HUB is not selected, it's an error
  9285. if (ps->HubName == NULL)
  9286. {
  9287. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9288. return ERR_INVALID_PARAMETER;
  9289. }
  9290. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  9291. if (o == NULL)
  9292. {
  9293. return ERR_INVALID_PARAMETER;
  9294. }
  9295. tmp = GetParamStr(o, "[security|packet]");
  9296. if (StartWith(tmp, "p"))
  9297. {
  9298. packet_log = true;
  9299. }
  9300. else if (StartWith(tmp, "s") == false)
  9301. {
  9302. c->Write(c, _UU("CMD_LogEnable_Prompt_Error"));
  9303. FreeParamValueList(o);
  9304. return ret;
  9305. }
  9306. Zero(&t, sizeof(t));
  9307. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9308. // RPC call
  9309. ret = ScGetHubLog(ps->Rpc, &t);
  9310. if (ret != ERR_NO_ERROR)
  9311. {
  9312. // An error has occured
  9313. CmdPrintError(c, ret);
  9314. FreeParamValueList(o);
  9315. return ret;
  9316. }
  9317. if (packet_log == false)
  9318. {
  9319. t.LogSetting.SaveSecurityLog = true;
  9320. }
  9321. else
  9322. {
  9323. t.LogSetting.SavePacketLog = true;
  9324. }
  9325. // RPC call
  9326. ret = ScSetHubLog(ps->Rpc, &t);
  9327. if (ret != ERR_NO_ERROR)
  9328. {
  9329. // An error has occured
  9330. CmdPrintError(c, ret);
  9331. FreeParamValueList(o);
  9332. return ret;
  9333. }
  9334. FreeParamValueList(o);
  9335. return 0;
  9336. }
  9337. // Disable the packet log or the security log
  9338. UINT PsLogDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9339. {
  9340. LIST *o;
  9341. PS *ps = (PS *)param;
  9342. UINT ret = 0;
  9343. RPC_HUB_LOG t;
  9344. bool packet_log = false;
  9345. char *tmp;
  9346. // Parameter list that can be specified
  9347. PARAM args[] =
  9348. {
  9349. {"[security|packet]", CmdPrompt, _UU("CMD_LogEnable_Prompt"), CmdEvalNotEmpty, NULL},
  9350. };
  9351. // If virtual HUB is not selected, it's an error
  9352. if (ps->HubName == NULL)
  9353. {
  9354. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9355. return ERR_INVALID_PARAMETER;
  9356. }
  9357. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  9358. if (o == NULL)
  9359. {
  9360. return ERR_INVALID_PARAMETER;
  9361. }
  9362. tmp = GetParamStr(o, "[security|packet]");
  9363. if (StartWith(tmp, "p"))
  9364. {
  9365. packet_log = true;
  9366. }
  9367. else if (StartWith(tmp, "s") == false)
  9368. {
  9369. c->Write(c, _UU("CMD_LogEnable_Prompt_Error"));
  9370. FreeParamValueList(o);
  9371. return ERR_INVALID_PARAMETER;
  9372. }
  9373. Zero(&t, sizeof(t));
  9374. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9375. // RPC call
  9376. ret = ScGetHubLog(ps->Rpc, &t);
  9377. if (ret != ERR_NO_ERROR)
  9378. {
  9379. // An error has occured
  9380. CmdPrintError(c, ret);
  9381. FreeParamValueList(o);
  9382. return ret;
  9383. }
  9384. if (packet_log == false)
  9385. {
  9386. t.LogSetting.SaveSecurityLog = false;
  9387. }
  9388. else
  9389. {
  9390. t.LogSetting.SavePacketLog = false;
  9391. }
  9392. // RPC call
  9393. ret = ScSetHubLog(ps->Rpc, &t);
  9394. if (ret != ERR_NO_ERROR)
  9395. {
  9396. // An error has occured
  9397. CmdPrintError(c, ret);
  9398. FreeParamValueList(o);
  9399. return ret;
  9400. }
  9401. FreeParamValueList(o);
  9402. return 0;
  9403. }
  9404. // Convert the string to log switching type
  9405. UINT StrToLogSwitchType(char *str)
  9406. {
  9407. UINT ret = INFINITE;
  9408. // Validate arguments
  9409. if (str == NULL)
  9410. {
  9411. return INFINITE;
  9412. }
  9413. if (IsEmptyStr(str) || StartWith("none", str))
  9414. {
  9415. ret = LOG_SWITCH_NO;
  9416. }
  9417. else if (StartWith("second", str))
  9418. {
  9419. ret = LOG_SWITCH_SECOND;
  9420. }
  9421. else if (StartWith("minute", str))
  9422. {
  9423. ret = LOG_SWITCH_MINUTE;
  9424. }
  9425. else if (StartWith("hour", str))
  9426. {
  9427. ret = LOG_SWITCH_HOUR;
  9428. }
  9429. else if (StartWith("day", str))
  9430. {
  9431. ret = LOG_SWITCH_DAY;
  9432. }
  9433. else if (StartWith("month", str))
  9434. {
  9435. ret = LOG_SWITCH_MONTH;
  9436. }
  9437. return ret;
  9438. }
  9439. // Set the switching period of the log file
  9440. UINT PsLogSwitchSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9441. {
  9442. LIST *o;
  9443. PS *ps = (PS *)param;
  9444. UINT ret = 0;
  9445. RPC_HUB_LOG t;
  9446. bool packet_log = false;
  9447. char *tmp;
  9448. UINT new_switch_type = 0;
  9449. // Parameter list that can be specified
  9450. PARAM args[] =
  9451. {
  9452. {"[security|packet]", CmdPrompt, _UU("CMD_LogEnable_Prompt"), CmdEvalNotEmpty, NULL},
  9453. {"SWITCH", CmdPrompt, _UU("CMD_LogSwitchSet_Prompt"), NULL, NULL},
  9454. };
  9455. // If virtual HUB is not selected, it's an error
  9456. if (ps->HubName == NULL)
  9457. {
  9458. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9459. return ERR_INVALID_PARAMETER;
  9460. }
  9461. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  9462. if (o == NULL)
  9463. {
  9464. return ERR_INVALID_PARAMETER;
  9465. }
  9466. tmp = GetParamStr(o, "[security|packet]");
  9467. if (StartWith(tmp, "p"))
  9468. {
  9469. packet_log = true;
  9470. }
  9471. else if (StartWith(tmp, "s") == false)
  9472. {
  9473. c->Write(c, _UU("CMD_LogEnable_Prompt_Error"));
  9474. FreeParamValueList(o);
  9475. return ERR_INVALID_PARAMETER;
  9476. }
  9477. new_switch_type = StrToLogSwitchType(GetParamStr(o, "SWITCH"));
  9478. if (new_switch_type == INFINITE)
  9479. {
  9480. c->Write(c, _UU("CMD_LogEnable_Prompt_Error"));
  9481. FreeParamValueList(o);
  9482. return ERR_INVALID_PARAMETER;
  9483. }
  9484. Zero(&t, sizeof(t));
  9485. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9486. // RPC call
  9487. ret = ScGetHubLog(ps->Rpc, &t);
  9488. if (ret != ERR_NO_ERROR)
  9489. {
  9490. // An error has occured
  9491. CmdPrintError(c, ret);
  9492. FreeParamValueList(o);
  9493. return ret;
  9494. }
  9495. if (packet_log == false)
  9496. {
  9497. t.LogSetting.SecurityLogSwitchType = new_switch_type;
  9498. }
  9499. else
  9500. {
  9501. t.LogSetting.PacketLogSwitchType = new_switch_type;
  9502. }
  9503. // RPC call
  9504. ret = ScSetHubLog(ps->Rpc, &t);
  9505. if (ret != ERR_NO_ERROR)
  9506. {
  9507. // An error has occured
  9508. CmdPrintError(c, ret);
  9509. FreeParamValueList(o);
  9510. return ret;
  9511. }
  9512. FreeParamValueList(o);
  9513. return 0;
  9514. }
  9515. // Convert the type string of the packet log contents to an integer
  9516. UINT StrToPacketLogSaveInfoType(char *str)
  9517. {
  9518. UINT ret = INFINITE;
  9519. if (str == NULL)
  9520. {
  9521. return INFINITE;
  9522. }
  9523. if (StartWith("none", str) || IsEmptyStr(str))
  9524. {
  9525. ret = PACKET_LOG_NONE;
  9526. }
  9527. else if (StartWith("header", str))
  9528. {
  9529. ret = PACKET_LOG_HEADER;
  9530. }
  9531. else if (StartWith("full", str) || StartWith("all", str))
  9532. {
  9533. ret = PACKET_LOG_ALL;
  9534. }
  9535. return ret;
  9536. }
  9537. // Convert a packet type string of the packet log to an integer
  9538. UINT StrToPacketLogType(char *str)
  9539. {
  9540. UINT ret = INFINITE;
  9541. if (str == NULL || IsEmptyStr(str))
  9542. {
  9543. return INFINITE;
  9544. }
  9545. if (StartWith("tcpconn", str))
  9546. {
  9547. ret = PACKET_LOG_TCP_CONN;
  9548. }
  9549. else if (StartWith("tcpdata", str))
  9550. {
  9551. ret = PACKET_LOG_TCP;
  9552. }
  9553. else if (StartWith("dhcp", str))
  9554. {
  9555. ret = PACKET_LOG_DHCP;
  9556. }
  9557. else if (StartWith("udp", str))
  9558. {
  9559. ret = PACKET_LOG_UDP;
  9560. }
  9561. else if (StartWith("icmp", str))
  9562. {
  9563. ret = PACKET_LOG_ICMP;
  9564. }
  9565. else if (StartWith("ip", str))
  9566. {
  9567. ret = PACKET_LOG_IP;
  9568. }
  9569. else if (StartWith("arp", str))
  9570. {
  9571. ret = PACKET_LOG_ARP;
  9572. }
  9573. else if (StartWith("ethernet", str))
  9574. {
  9575. ret = PACKET_LOG_ETHERNET;
  9576. }
  9577. return ret;
  9578. }
  9579. // Set the detail level and type of packet to be stored in the packet log
  9580. UINT PsLogPacketSaveType(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9581. {
  9582. LIST *o;
  9583. PS *ps = (PS *)param;
  9584. UINT ret = 0;
  9585. RPC_HUB_LOG t;
  9586. bool packet_log = false;
  9587. UINT packet_type = INFINITE;
  9588. UINT packet_save_info_type = INFINITE;
  9589. // Parameter list that can be specified
  9590. PARAM args[] =
  9591. {
  9592. {"TYPE", CmdPrompt, _UU("CMD_LogPacketSaveType_Prompt_TYPE"), NULL, NULL},
  9593. {"SAVE", CmdPrompt, _UU("CMD_LogPacketSaveType_Prompt_SAVE"), NULL, NULL},
  9594. };
  9595. // If virtual HUB is not selected, it's an error
  9596. if (ps->HubName == NULL)
  9597. {
  9598. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9599. return ERR_INVALID_PARAMETER;
  9600. }
  9601. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  9602. if (o == NULL)
  9603. {
  9604. return ERR_INVALID_PARAMETER;
  9605. }
  9606. packet_type = StrToPacketLogType(GetParamStr(o, "TYPE"));
  9607. packet_save_info_type = StrToPacketLogSaveInfoType(GetParamStr(o, "SAVE"));
  9608. if (packet_type == INFINITE || packet_save_info_type == INFINITE)
  9609. {
  9610. c->Write(c, _UU("CMD_LogEnable_Prompt_Error"));
  9611. FreeParamValueList(o);
  9612. return ERR_INVALID_PARAMETER;
  9613. }
  9614. Zero(&t, sizeof(t));
  9615. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9616. // RPC call
  9617. ret = ScGetHubLog(ps->Rpc, &t);
  9618. if (ret != ERR_NO_ERROR)
  9619. {
  9620. // An error has occured
  9621. CmdPrintError(c, ret);
  9622. FreeParamValueList(o);
  9623. return ret;
  9624. }
  9625. t.LogSetting.PacketLogConfig[packet_type] = packet_save_info_type;
  9626. // RPC call
  9627. ret = ScSetHubLog(ps->Rpc, &t);
  9628. if (ret != ERR_NO_ERROR)
  9629. {
  9630. // An error has occured
  9631. CmdPrintError(c, ret);
  9632. FreeParamValueList(o);
  9633. return ret;
  9634. }
  9635. FreeParamValueList(o);
  9636. return 0;
  9637. }
  9638. // Get the list of certificates of the trusted certification authority
  9639. UINT PsCAList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9640. {
  9641. LIST *o;
  9642. PS *ps = (PS *)param;
  9643. UINT ret = 0;
  9644. RPC_HUB_ENUM_CA t;
  9645. // If virtual HUB is not selected, it's an error
  9646. if (ps->HubName == NULL)
  9647. {
  9648. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9649. return ERR_INVALID_PARAMETER;
  9650. }
  9651. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  9652. if (o == NULL)
  9653. {
  9654. return ERR_INVALID_PARAMETER;
  9655. }
  9656. Zero(&t, sizeof(t));
  9657. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9658. // RPC call
  9659. ret = ScEnumCa(ps->Rpc, &t);
  9660. if (ret != ERR_NO_ERROR)
  9661. {
  9662. // An error has occured
  9663. CmdPrintError(c, ret);
  9664. FreeParamValueList(o);
  9665. return ret;
  9666. }
  9667. else
  9668. {
  9669. UINT i;
  9670. CT *ct = CtNewStandard();
  9671. for (i = 0;i < t.NumCa;i++)
  9672. {
  9673. wchar_t tmp[MAX_SIZE];
  9674. wchar_t tmp2[64];
  9675. RPC_HUB_ENUM_CA_ITEM *e = &t.Ca[i];
  9676. GetDateStrEx64(tmp, sizeof(tmp), SystemToLocal64(e->Expires), NULL);
  9677. UniToStru(tmp2, e->Key);
  9678. CtInsert(ct, _UU("CMD_CAList_COLUMN_ID"), tmp2);
  9679. CtInsert(ct, _UU("CM_CERT_COLUMN_1"), e->SubjectName);
  9680. CtInsert(ct, _UU("CM_CERT_COLUMN_2"), e->IssuerName);
  9681. CtInsert(ct, _UU("CM_CERT_COLUMN_3"), tmp);
  9682. if (i != (t.NumCa - 1))
  9683. {
  9684. CtInsert(ct, L"---", L"---");
  9685. }
  9686. }
  9687. CtFree(ct, c);
  9688. }
  9689. FreeRpcHubEnumCa(&t);
  9690. FreeParamValueList(o);
  9691. return 0;
  9692. }
  9693. // Add a certificate to the trusted certification authority
  9694. UINT PsCAAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9695. {
  9696. LIST *o;
  9697. PS *ps = (PS *)param;
  9698. UINT ret = 0;
  9699. RPC_HUB_ADD_CA t;
  9700. X *x;
  9701. // Parameter list that can be specified
  9702. PARAM args[] =
  9703. {
  9704. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  9705. {"[path]", CmdPrompt, _UU("CMD_CAAdd_PROMPT_PATH"), CmdEvalIsFile, NULL},
  9706. };
  9707. // If virtual HUB is not selected, it's an error
  9708. if (ps->HubName == NULL)
  9709. {
  9710. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9711. return ERR_INVALID_PARAMETER;
  9712. }
  9713. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  9714. if (o == NULL)
  9715. {
  9716. return ERR_INVALID_PARAMETER;
  9717. }
  9718. x = FileToXW(GetParamUniStr(o, "[path]"));
  9719. if (x == NULL)
  9720. {
  9721. FreeParamValueList(o);
  9722. c->Write(c, _UU("CMD_MSG_LOAD_CERT_FAILED"));
  9723. return ERR_INVALID_PARAMETER;
  9724. }
  9725. Zero(&t, sizeof(t));
  9726. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9727. t.Cert = x;
  9728. // RPC call
  9729. ret = ScAddCa(ps->Rpc, &t);
  9730. if (ret != ERR_NO_ERROR)
  9731. {
  9732. // An error has occured
  9733. CmdPrintError(c, ret);
  9734. FreeParamValueList(o);
  9735. return ret;
  9736. }
  9737. FreeRpcHubAddCa(&t);
  9738. FreeParamValueList(o);
  9739. return 0;
  9740. }
  9741. // Delete the certificate of the trusted certification authority
  9742. UINT PsCADelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9743. {
  9744. LIST *o;
  9745. PS *ps = (PS *)param;
  9746. UINT ret = 0;
  9747. RPC_HUB_DELETE_CA t;
  9748. // Parameter list that can be specified
  9749. PARAM args[] =
  9750. {
  9751. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  9752. {"[id]", CmdPrompt, _UU("CMD_CADelete_PROMPT_ID"), CmdEvalNotEmpty, NULL},
  9753. };
  9754. // If virtual HUB is not selected, it's an error
  9755. if (ps->HubName == NULL)
  9756. {
  9757. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9758. return ERR_INVALID_PARAMETER;
  9759. }
  9760. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  9761. if (o == NULL)
  9762. {
  9763. return ERR_INVALID_PARAMETER;
  9764. }
  9765. Zero(&t, sizeof(t));
  9766. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9767. t.Key = GetParamInt(o, "[id]");
  9768. // RPC call
  9769. ret = ScDeleteCa(ps->Rpc, &t);
  9770. if (ret != ERR_NO_ERROR)
  9771. {
  9772. // An error has occured
  9773. CmdPrintError(c, ret);
  9774. FreeParamValueList(o);
  9775. return ret;
  9776. }
  9777. FreeParamValueList(o);
  9778. return 0;
  9779. }
  9780. // Get the certificate of the trusted certification authority
  9781. UINT PsCAGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9782. {
  9783. LIST *o;
  9784. PS *ps = (PS *)param;
  9785. UINT ret = 0;
  9786. RPC_HUB_GET_CA t;
  9787. // Parameter list that can be specified
  9788. PARAM args[] =
  9789. {
  9790. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  9791. {"[id]", CmdPrompt, _UU("CMD_CAGet_PROMPT_ID"), CmdEvalNotEmpty, NULL},
  9792. {"SAVECERT", CmdPrompt, _UU("CMD_CAGet_PROMPT_SAVECERT"), CmdEvalNotEmpty, NULL},
  9793. };
  9794. // If virtual HUB is not selected, it's an error
  9795. if (ps->HubName == NULL)
  9796. {
  9797. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9798. return ERR_INVALID_PARAMETER;
  9799. }
  9800. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  9801. if (o == NULL)
  9802. {
  9803. return ERR_INVALID_PARAMETER;
  9804. }
  9805. Zero(&t, sizeof(t));
  9806. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9807. t.Key = GetParamInt(o, "[id]");
  9808. // RPC call
  9809. ret = ScGetCa(ps->Rpc, &t);
  9810. if (ret != ERR_NO_ERROR)
  9811. {
  9812. // An error has occured
  9813. CmdPrintError(c, ret);
  9814. FreeParamValueList(o);
  9815. return ret;
  9816. }
  9817. else
  9818. {
  9819. if (XToFileW(t.Cert, GetParamUniStr(o, "SAVECERT"), true))
  9820. {
  9821. // Success
  9822. }
  9823. else
  9824. {
  9825. ret = ERR_INTERNAL_ERROR;
  9826. c->Write(c, _UU("CMD_MSG_SAVE_CERT_FAILED"));
  9827. }
  9828. }
  9829. FreeRpcHubGetCa(&t);
  9830. FreeParamValueList(o);
  9831. return ret;
  9832. }
  9833. // Get the cascade connection list
  9834. UINT PsCascadeList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9835. {
  9836. LIST *o;
  9837. PS *ps = (PS *)param;
  9838. UINT ret = 0;
  9839. RPC_ENUM_LINK t;
  9840. // If virtual HUB is not selected, it's an error
  9841. if (ps->HubName == NULL)
  9842. {
  9843. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9844. return ERR_INVALID_PARAMETER;
  9845. }
  9846. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  9847. if (o == NULL)
  9848. {
  9849. return ERR_INVALID_PARAMETER;
  9850. }
  9851. Zero(&t, sizeof(t));
  9852. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9853. // RPC call
  9854. ret = ScEnumLink(ps->Rpc, &t);
  9855. if (ret != ERR_NO_ERROR)
  9856. {
  9857. // An error has occured
  9858. CmdPrintError(c, ret);
  9859. FreeParamValueList(o);
  9860. return ret;
  9861. }
  9862. else
  9863. {
  9864. CT *ct = CtNew();
  9865. UINT i;
  9866. CtInsertColumn(ct, _UU("SM_LINK_COLUMN_1"), false);
  9867. CtInsertColumn(ct, _UU("SM_LINK_COLUMN_2"), false);
  9868. CtInsertColumn(ct, _UU("SM_LINK_COLUMN_3"), false);
  9869. CtInsertColumn(ct, _UU("SM_LINK_COLUMN_4"), false);
  9870. CtInsertColumn(ct, _UU("SM_LINK_COLUMN_5"), false);
  9871. for (i = 0;i < t.NumLink;i++)
  9872. {
  9873. RPC_ENUM_LINK_ITEM *e = &t.Links[i];
  9874. wchar_t tmp1[MAX_SIZE];
  9875. wchar_t tmp2[MAX_SIZE];
  9876. wchar_t tmp3[MAX_SIZE];
  9877. wchar_t tmp4[MAX_SIZE];
  9878. GetDateTimeStrEx64(tmp1, sizeof(tmp1), SystemToLocal64(e->ConnectedTime), NULL);
  9879. StrToUni(tmp2, sizeof(tmp2), e->Hostname);
  9880. StrToUni(tmp3, sizeof(tmp3), e->HubName);
  9881. if (e->Online == false)
  9882. {
  9883. UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_LINK_STATUS_OFFLINE"));
  9884. }
  9885. else
  9886. {
  9887. if (e->Connected)
  9888. {
  9889. UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_LINK_STATUS_ONLINE"));
  9890. }
  9891. else
  9892. {
  9893. if (e->LastError != 0)
  9894. {
  9895. UniFormat(tmp4, sizeof(tmp4), _UU("SM_LINK_STATUS_ERROR"), e->LastError, _E(e->LastError));
  9896. }
  9897. else
  9898. {
  9899. UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_LINK_CONNECTING"));
  9900. }
  9901. }
  9902. }
  9903. CtInsert(ct, e->AccountName, tmp4, tmp1, tmp2, tmp3);
  9904. }
  9905. CtFreeEx(ct, c, true);
  9906. }
  9907. FreeRpcEnumLink(&t);
  9908. FreeParamValueList(o);
  9909. return 0;
  9910. }
  9911. // Creat a new cascade
  9912. UINT PsCascadeCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9913. {
  9914. LIST *o;
  9915. PS *ps = (PS *)param;
  9916. UINT ret = 0;
  9917. RPC_CREATE_LINK t;
  9918. char *host = NULL;
  9919. UINT port = 443;
  9920. // Parameter list that can be specified
  9921. PARAM args[] =
  9922. {
  9923. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  9924. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  9925. {"SERVER", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Server"), CmdEvalHostAndPort, NULL},
  9926. {"HUB", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Hub"), CmdEvalSafe, NULL},
  9927. {"USERNAME", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Username"), CmdEvalNotEmpty, NULL},
  9928. };
  9929. // If virtual HUB is not selected, it's an error
  9930. if (ps->HubName == NULL)
  9931. {
  9932. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9933. return ERR_INVALID_PARAMETER;
  9934. }
  9935. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  9936. if (o == NULL)
  9937. {
  9938. return ERR_INVALID_PARAMETER;
  9939. }
  9940. ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 443);
  9941. Zero(&t, sizeof(t));
  9942. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  9943. t.Online = false;
  9944. Copy(&t.Policy, GetDefaultPolicy(), sizeof(POLICY));
  9945. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  9946. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  9947. t.ClientOption->Port = port;
  9948. StrCpy(t.ClientOption->Hostname, sizeof(t.ClientOption->Hostname), host);
  9949. StrCpy(t.ClientOption->HubName, sizeof(t.ClientOption->HubName), GetParamStr(o, "HUB"));
  9950. t.ClientOption->NumRetry = INFINITE;
  9951. t.ClientOption->RetryInterval = 15;
  9952. t.ClientOption->MaxConnection = 8;
  9953. t.ClientOption->UseEncrypt = true;
  9954. t.ClientOption->AdditionalConnectionInterval = 1;
  9955. t.ClientOption->RequireBridgeRoutingMode = true;
  9956. t.ClientAuth = ZeroMalloc(sizeof(CLIENT_AUTH));
  9957. t.ClientAuth->AuthType = CLIENT_AUTHTYPE_ANONYMOUS;
  9958. StrCpy(t.ClientAuth->Username, sizeof(t.ClientAuth->Username), GetParamStr(o, "USERNAME"));
  9959. Free(host);
  9960. // RPC call
  9961. ret = ScCreateLink(ps->Rpc, &t);
  9962. if (ret != ERR_NO_ERROR)
  9963. {
  9964. // An error has occured
  9965. CmdPrintError(c, ret);
  9966. FreeParamValueList(o);
  9967. return ret;
  9968. }
  9969. FreeRpcCreateLink(&t);
  9970. FreeParamValueList(o);
  9971. return 0;
  9972. }
  9973. // Set the user name and destination of the cascade connection
  9974. UINT PsCascadeSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  9975. {
  9976. LIST *o;
  9977. PS *ps = (PS *)param;
  9978. UINT ret = 0;
  9979. RPC_CREATE_LINK t;
  9980. char *host = NULL;
  9981. UINT port = 443;
  9982. // Parameter list that can be specified
  9983. PARAM args[] =
  9984. {
  9985. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  9986. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  9987. {"SERVER", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Server"), CmdEvalHostAndPort, NULL},
  9988. {"HUB", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Hub"), CmdEvalSafe, NULL},
  9989. };
  9990. // If virtual HUB is not selected, it's an error
  9991. if (ps->HubName == NULL)
  9992. {
  9993. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  9994. return ERR_INVALID_PARAMETER;
  9995. }
  9996. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  9997. if (o == NULL)
  9998. {
  9999. return ERR_INVALID_PARAMETER;
  10000. }
  10001. ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 443);
  10002. Zero(&t, sizeof(t));
  10003. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10004. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10005. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10006. ret = ScGetLink(ps->Rpc, &t);
  10007. if (ret != ERR_NO_ERROR)
  10008. {
  10009. // An error has occured
  10010. CmdPrintError(c, ret);
  10011. FreeParamValueList(o);
  10012. Free(host);
  10013. return ret;
  10014. }
  10015. t.ClientOption->Port = port;
  10016. StrCpy(t.ClientOption->Hostname, sizeof(t.ClientOption->Hostname), host);
  10017. StrCpy(t.ClientOption->HubName, sizeof(t.ClientOption->HubName), GetParamStr(o, "HUB"));
  10018. Free(host);
  10019. // RPC call
  10020. ret = ScSetLink(ps->Rpc, &t);
  10021. if (ret != ERR_NO_ERROR)
  10022. {
  10023. // An error has occured
  10024. CmdPrintError(c, ret);
  10025. FreeParamValueList(o);
  10026. return ret;
  10027. }
  10028. FreeRpcCreateLink(&t);
  10029. FreeParamValueList(o);
  10030. return 0;
  10031. }
  10032. // Get the type string of proxy
  10033. wchar_t *GetProxyTypeStr(UINT i)
  10034. {
  10035. switch (i)
  10036. {
  10037. case PROXY_DIRECT:
  10038. return _UU("PROTO_DIRECT_TCP");
  10039. case PROXY_HTTP:
  10040. return _UU("PROTO_HTTP_PROXY");
  10041. case PROXY_SOCKS:
  10042. return _UU("PROTO_SOCKS_PROXY");
  10043. default:
  10044. return _UU("PROTO_UNKNOWN");
  10045. }
  10046. }
  10047. // Get type string in user authentication for client
  10048. wchar_t *GetClientAuthTypeStr(UINT i)
  10049. {
  10050. char tmp[MAX_SIZE];
  10051. Format(tmp, sizeof(tmp), "PW_TYPE_%u", i);
  10052. return _UU(tmp);
  10053. }
  10054. // Get the setting of cascade connection
  10055. UINT PsCascadeGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10056. {
  10057. LIST *o;
  10058. PS *ps = (PS *)param;
  10059. UINT ret = 0;
  10060. RPC_CREATE_LINK t;
  10061. // Parameter list that can be specified
  10062. PARAM args[] =
  10063. {
  10064. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  10065. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10066. };
  10067. // If virtual HUB is not selected, it's an error
  10068. if (ps->HubName == NULL)
  10069. {
  10070. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10071. return ERR_INVALID_PARAMETER;
  10072. }
  10073. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10074. if (o == NULL)
  10075. {
  10076. return ERR_INVALID_PARAMETER;
  10077. }
  10078. Zero(&t, sizeof(t));
  10079. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10080. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10081. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName),
  10082. GetParamUniStr(o, "[name]"));
  10083. // RPC call
  10084. ret = ScGetLink(ps->Rpc, &t);
  10085. if (ret != ERR_NO_ERROR)
  10086. {
  10087. // An error has occured
  10088. CmdPrintError(c, ret);
  10089. FreeParamValueList(o);
  10090. return ret;
  10091. }
  10092. else
  10093. {
  10094. // Show the contents of the connection settings
  10095. wchar_t tmp[MAX_SIZE];
  10096. CT *ct = CtNewStandard();
  10097. // Connection settings name
  10098. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NAME"), t.ClientOption->AccountName);
  10099. // Host name of the destination VPN Server
  10100. StrToUni(tmp, sizeof(tmp), t.ClientOption->Hostname);
  10101. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_HOSTNAME"), tmp);
  10102. // The port number to connect to VPN Server
  10103. UniToStru(tmp, t.ClientOption->Port);
  10104. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PORT"), tmp);
  10105. // Virtual HUB name of the destination VPN Server
  10106. StrToUni(tmp, sizeof(tmp), t.ClientOption->HubName);
  10107. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_HUBNAME"), tmp);
  10108. // Type of proxy server to go through
  10109. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_TYPE"), GetProxyTypeStr(t.ClientOption->ProxyType));
  10110. if (t.ClientOption->ProxyType != PROXY_DIRECT)
  10111. {
  10112. // Host name of the proxy server
  10113. StrToUni(tmp, sizeof(tmp), t.ClientOption->ProxyName);
  10114. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_HOSTNAME"), tmp);
  10115. // Port number of the proxy server
  10116. UniToStru(tmp, t.ClientOption->ProxyPort);
  10117. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_PORT"), tmp);
  10118. // User name of the proxy server
  10119. StrToUni(tmp, sizeof(tmp), t.ClientOption->ProxyUsername);
  10120. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_PROXY_USERNAME"), tmp);
  10121. }
  10122. // To verify the server certificate
  10123. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_SERVER_CERT_USE"),
  10124. t.CheckServerCert ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  10125. // Registered specific certificate
  10126. if (t.ServerCert != NULL)
  10127. {
  10128. GetAllNameFromX(tmp, sizeof(tmp), t.ServerCert);
  10129. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_SERVER_CERT_NAME"), tmp);
  10130. }
  10131. // Device name to be used for the connection
  10132. StrToUni(tmp, sizeof(tmp), t.ClientOption->DeviceName);
  10133. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_DEVICE_NAME"), tmp);
  10134. // Authentication type
  10135. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_AUTH_TYPE"), GetClientAuthTypeStr(t.ClientAuth->AuthType));
  10136. // User name
  10137. StrToUni(tmp, sizeof(tmp), t.ClientAuth->Username);
  10138. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_AUTH_USERNAME"), tmp);
  10139. if (t.ClientAuth->AuthType == CLIENT_AUTHTYPE_CERT)
  10140. {
  10141. if (t.ClientAuth->ClientX != NULL)
  10142. {
  10143. // Client certificate name
  10144. GetAllNameFromX(tmp, sizeof(tmp), t.ClientAuth->ClientX);
  10145. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_AUTH_CERT_NAME"), tmp);
  10146. }
  10147. }
  10148. // Number of TCP connections to be used for VPN communication
  10149. UniToStru(tmp, t.ClientOption->MaxConnection);
  10150. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NUMTCP"), tmp);
  10151. // Establishment interval of each TCP connection
  10152. UniToStru(tmp, t.ClientOption->AdditionalConnectionInterval);
  10153. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_TCP_INTERVAL"), tmp);
  10154. // Life span of each TCP connection
  10155. if (t.ClientOption->ConnectionDisconnectSpan != 0)
  10156. {
  10157. UniToStru(tmp, t.ClientOption->ConnectionDisconnectSpan);
  10158. }
  10159. else
  10160. {
  10161. UniStrCpy(tmp, sizeof(tmp), _UU("CMD_MSG_INFINITE"));
  10162. }
  10163. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_TCP_TTL"), tmp);
  10164. // Use of half-duplex mode
  10165. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_TCP_HALF"),
  10166. t.ClientOption->HalfConnection ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  10167. // Encryption by SSL
  10168. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_ENCRYPT"),
  10169. t.ClientOption->UseEncrypt ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  10170. // Data compression
  10171. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_COMPRESS"),
  10172. t.ClientOption->UseCompress ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  10173. // Connect in bridge / router mode
  10174. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_BRIDGE_ROUTER"),
  10175. t.ClientOption->RequireBridgeRoutingMode ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  10176. // Connect in monitoring mode
  10177. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_MONITOR"),
  10178. t.ClientOption->RequireMonitorMode ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  10179. // Not to rewrite the routing table
  10180. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_NO_TRACKING"),
  10181. t.ClientOption->NoRoutingTracking ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  10182. // Disable the QoS control
  10183. CtInsert(ct, _UU("CMD_ACCOUNT_COLUMN_QOS_DISABLE"),
  10184. t.ClientOption->DisableQoS ? _UU("CMD_MSG_ENABLE") : _UU("CMD_MSG_DISABLE"));
  10185. CtFree(ct, c);
  10186. // Security policy
  10187. c->Write(c, L"");
  10188. c->Write(c, _UU("CMD_CascadeGet_Policy"));
  10189. PrintPolicy(c, &t.Policy, true);
  10190. }
  10191. FreeRpcCreateLink(&t);
  10192. FreeParamValueList(o);
  10193. return 0;
  10194. }
  10195. // Delete the cascade connection
  10196. UINT PsCascadeDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10197. {
  10198. LIST *o;
  10199. PS *ps = (PS *)param;
  10200. UINT ret = 0;
  10201. RPC_LINK t;
  10202. // Parameter list that can be specified
  10203. PARAM args[] =
  10204. {
  10205. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10206. };
  10207. // If virtual HUB is not selected, it's an error
  10208. if (ps->HubName == NULL)
  10209. {
  10210. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10211. return ERR_INVALID_PARAMETER;
  10212. }
  10213. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10214. if (o == NULL)
  10215. {
  10216. return ERR_INVALID_PARAMETER;
  10217. }
  10218. Zero(&t, sizeof(t));
  10219. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  10220. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10221. // RPC call
  10222. ret = ScDeleteLink(ps->Rpc, &t);
  10223. if (ret != ERR_NO_ERROR)
  10224. {
  10225. // An error has occured
  10226. CmdPrintError(c, ret);
  10227. FreeParamValueList(o);
  10228. return ret;
  10229. }
  10230. FreeParamValueList(o);
  10231. return 0;
  10232. }
  10233. // Set the user name to use for the cascade connection
  10234. UINT PsCascadeUsernameSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10235. {
  10236. LIST *o;
  10237. PS *ps = (PS *)param;
  10238. UINT ret = 0;
  10239. RPC_CREATE_LINK t;
  10240. // Parameter list that can be specified
  10241. PARAM args[] =
  10242. {
  10243. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10244. {"USERNAME", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Username"), CmdEvalNotEmpty, NULL},
  10245. };
  10246. // If virtual HUB is not selected, it's an error
  10247. if (ps->HubName == NULL)
  10248. {
  10249. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10250. return ERR_INVALID_PARAMETER;
  10251. }
  10252. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10253. if (o == NULL)
  10254. {
  10255. return ERR_INVALID_PARAMETER;
  10256. }
  10257. Zero(&t, sizeof(t));
  10258. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10259. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10260. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10261. // RPC call
  10262. ret = ScGetLink(ps->Rpc, &t);
  10263. if (ret != ERR_NO_ERROR)
  10264. {
  10265. // An error has occured
  10266. CmdPrintError(c, ret);
  10267. FreeParamValueList(o);
  10268. return ret;
  10269. }
  10270. else
  10271. {
  10272. // Change the settings for the cascade connection
  10273. StrCpy(t.ClientAuth->Username, sizeof(t.ClientAuth->Username),
  10274. GetParamStr(o, "USERNAME"));
  10275. if (t.ClientAuth->AuthType == CLIENT_AUTHTYPE_PASSWORD)
  10276. {
  10277. c->Write(c, _UU("CMD_CascadeUsername_Notice"));
  10278. }
  10279. ret = ScSetLink(ps->Rpc, &t);
  10280. if (ret != ERR_NO_ERROR)
  10281. {
  10282. // An error has occured
  10283. CmdPrintError(c, ret);
  10284. FreeParamValueList(o);
  10285. return ret;
  10286. }
  10287. FreeRpcCreateLink(&t);
  10288. }
  10289. FreeParamValueList(o);
  10290. return 0;
  10291. }
  10292. //Set the type of user authentication of cascade connection to the anonymous authentication
  10293. UINT PsCascadeAnonymousSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10294. {
  10295. LIST *o;
  10296. PS *ps = (PS *)param;
  10297. UINT ret = 0;
  10298. RPC_CREATE_LINK t;
  10299. // Parameter list that can be specified
  10300. PARAM args[] =
  10301. {
  10302. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10303. };
  10304. // If virtual HUB is not selected, it's an error
  10305. if (ps->HubName == NULL)
  10306. {
  10307. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10308. return ERR_INVALID_PARAMETER;
  10309. }
  10310. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10311. if (o == NULL)
  10312. {
  10313. return ERR_INVALID_PARAMETER;
  10314. }
  10315. Zero(&t, sizeof(t));
  10316. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10317. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10318. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10319. // RPC call
  10320. ret = ScGetLink(ps->Rpc, &t);
  10321. if (ret != ERR_NO_ERROR)
  10322. {
  10323. // An error has occured
  10324. CmdPrintError(c, ret);
  10325. FreeParamValueList(o);
  10326. return ret;
  10327. }
  10328. else
  10329. {
  10330. // Change the settings for the cascade connection
  10331. t.ClientAuth->AuthType = CLIENT_AUTHTYPE_ANONYMOUS;
  10332. ret = ScSetLink(ps->Rpc, &t);
  10333. if (ret != ERR_NO_ERROR)
  10334. {
  10335. // An error has occured
  10336. CmdPrintError(c, ret);
  10337. FreeParamValueList(o);
  10338. return ret;
  10339. }
  10340. FreeRpcCreateLink(&t);
  10341. }
  10342. FreeParamValueList(o);
  10343. return 0;
  10344. }
  10345. // Set the type of user authentication of cascade connection to the password authentication
  10346. UINT PsCascadePasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10347. {
  10348. LIST *o;
  10349. PS *ps = (PS *)param;
  10350. UINT ret = 0;
  10351. RPC_CREATE_LINK t;
  10352. // Parameter list that can be specified
  10353. PARAM args[] =
  10354. {
  10355. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10356. {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},
  10357. {"TYPE", CmdPrompt, _UU("CMD_CascadePasswordSet_Prompt_Type"), CmdEvalNotEmpty, NULL},
  10358. };
  10359. // If virtual HUB is not selected, it's an error
  10360. if (ps->HubName == NULL)
  10361. {
  10362. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10363. return ERR_INVALID_PARAMETER;
  10364. }
  10365. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10366. if (o == NULL)
  10367. {
  10368. return ERR_INVALID_PARAMETER;
  10369. }
  10370. Zero(&t, sizeof(t));
  10371. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10372. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10373. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10374. // RPC call
  10375. ret = ScGetLink(ps->Rpc, &t);
  10376. if (ret != ERR_NO_ERROR)
  10377. {
  10378. // An error has occured
  10379. CmdPrintError(c, ret);
  10380. FreeParamValueList(o);
  10381. return ret;
  10382. }
  10383. else
  10384. {
  10385. // Change the settings for the cascade connection
  10386. char *typestr = GetParamStr(o, "TYPE");
  10387. if (StartWith("standard", typestr))
  10388. {
  10389. t.ClientAuth->AuthType = CLIENT_AUTHTYPE_PASSWORD;
  10390. HashPassword(t.ClientAuth->HashedPassword, t.ClientAuth->Username,
  10391. GetParamStr(o, "PASSWORD"));
  10392. }
  10393. else if (StartWith("radius", typestr) || StartWith("ntdomain", typestr))
  10394. {
  10395. t.ClientAuth->AuthType = CLIENT_AUTHTYPE_PLAIN_PASSWORD;
  10396. StrCpy(t.ClientAuth->PlainPassword, sizeof(t.ClientAuth->PlainPassword),
  10397. GetParamStr(o, "PASSWORD"));
  10398. }
  10399. else
  10400. {
  10401. // An error has occured
  10402. c->Write(c, _UU("CMD_CascadePasswordSet_Type_Invalid"));
  10403. FreeRpcCreateLink(&t);
  10404. ret = ERR_INVALID_PARAMETER;
  10405. CmdPrintError(c, ret);
  10406. FreeParamValueList(o);
  10407. return ERR_INTERNAL_ERROR;
  10408. }
  10409. ret = ScSetLink(ps->Rpc, &t);
  10410. if (ret != ERR_NO_ERROR)
  10411. {
  10412. // An error has occured
  10413. CmdPrintError(c, ret);
  10414. FreeParamValueList(o);
  10415. return ret;
  10416. }
  10417. FreeRpcCreateLink(&t);
  10418. }
  10419. FreeParamValueList(o);
  10420. return 0;
  10421. }
  10422. // Set the type of user authentication of cascade connection to the client certificate authentication
  10423. UINT PsCascadeCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10424. {
  10425. LIST *o;
  10426. PS *ps = (PS *)param;
  10427. UINT ret = 0;
  10428. RPC_CREATE_LINK t;
  10429. X *x;
  10430. K *k;
  10431. // Parameter list that can be specified
  10432. PARAM args[] =
  10433. {
  10434. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  10435. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10436. {"LOADCERT", CmdPrompt, _UU("CMD_LOADCERTPATH"), CmdEvalIsFile, NULL},
  10437. {"LOADKEY", CmdPrompt, _UU("CMD_LOADKEYPATH"), CmdEvalIsFile, NULL},
  10438. };
  10439. // If virtual HUB is not selected, it's an error
  10440. if (ps->HubName == NULL)
  10441. {
  10442. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10443. return ERR_INVALID_PARAMETER;
  10444. }
  10445. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10446. if (o == NULL)
  10447. {
  10448. return ERR_INVALID_PARAMETER;
  10449. }
  10450. if (CmdLoadCertAndKey(c, &x, &k, GetParamUniStr(o, "LOADCERT"), GetParamUniStr(o, "LOADKEY")) == false)
  10451. {
  10452. return ERR_INTERNAL_ERROR;
  10453. }
  10454. Zero(&t, sizeof(t));
  10455. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10456. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10457. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10458. // RPC call
  10459. ret = ScGetLink(ps->Rpc, &t);
  10460. if (ret != ERR_NO_ERROR)
  10461. {
  10462. // An error has occured
  10463. FreeX(x);
  10464. FreeK(k);
  10465. CmdPrintError(c, ret);
  10466. FreeParamValueList(o);
  10467. return ret;
  10468. }
  10469. else
  10470. {
  10471. // Change authentication data
  10472. t.ClientAuth->AuthType = CLIENT_AUTHTYPE_CERT;
  10473. if (t.ClientAuth->ClientX != NULL)
  10474. {
  10475. FreeX(t.ClientAuth->ClientX);
  10476. }
  10477. if (t.ClientAuth->ClientK != NULL)
  10478. {
  10479. FreeK(t.ClientAuth->ClientK);
  10480. }
  10481. t.ClientAuth->ClientX = x;
  10482. t.ClientAuth->ClientK = k;
  10483. ret = ScSetLink(ps->Rpc, &t);
  10484. if (ret != ERR_NO_ERROR)
  10485. {
  10486. // An error has occured
  10487. CmdPrintError(c, ret);
  10488. FreeParamValueList(o);
  10489. return ret;
  10490. }
  10491. FreeRpcCreateLink(&t);
  10492. }
  10493. FreeParamValueList(o);
  10494. return 0;
  10495. }
  10496. // Get the client certificate to be used in the cascade connection
  10497. UINT PsCascadeCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10498. {
  10499. LIST *o;
  10500. PS *ps = (PS *)param;
  10501. UINT ret = 0;
  10502. RPC_CREATE_LINK t;
  10503. // Parameter list that can be specified
  10504. PARAM args[] =
  10505. {
  10506. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  10507. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10508. {"SAVECERT", CmdPrompt, _UU("CMD_SAVECERTPATH"), CmdEvalNotEmpty, NULL},
  10509. };
  10510. // If virtual HUB is not selected, it's an error
  10511. if (ps->HubName == NULL)
  10512. {
  10513. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10514. return ERR_INVALID_PARAMETER;
  10515. }
  10516. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10517. if (o == NULL)
  10518. {
  10519. return ERR_INVALID_PARAMETER;
  10520. }
  10521. Zero(&t, sizeof(t));
  10522. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10523. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10524. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10525. // RPC call
  10526. ret = ScGetLink(ps->Rpc, &t);
  10527. if (ret != ERR_NO_ERROR)
  10528. {
  10529. // An error has occured
  10530. CmdPrintError(c, ret);
  10531. FreeParamValueList(o);
  10532. return ret;
  10533. }
  10534. else
  10535. {
  10536. if (t.ClientAuth->AuthType != CLIENT_AUTHTYPE_CERT)
  10537. {
  10538. c->Write(c, _UU("CMD_CascadeCertSet_Not_Auth_Cert"));
  10539. ret = ERR_INTERNAL_ERROR;
  10540. }
  10541. else if (t.ClientAuth->ClientX == NULL)
  10542. {
  10543. c->Write(c, _UU("CMD_CascadeCertSet_Cert_Not_Exists"));
  10544. ret = ERR_INTERNAL_ERROR;
  10545. }
  10546. else
  10547. {
  10548. XToFileW(t.ClientAuth->ClientX, GetParamUniStr(o, "SAVECERT"), true);
  10549. }
  10550. FreeRpcCreateLink(&t);
  10551. }
  10552. FreeParamValueList(o);
  10553. return ret;
  10554. }
  10555. // Enable encryption of communication at the time of the cascade connection
  10556. UINT PsCascadeEncryptEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10557. {
  10558. LIST *o;
  10559. PS *ps = (PS *)param;
  10560. UINT ret = 0;
  10561. RPC_CREATE_LINK t;
  10562. // Parameter list that can be specified
  10563. PARAM args[] =
  10564. {
  10565. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  10566. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10567. };
  10568. // If virtual HUB is not selected, it's an error
  10569. if (ps->HubName == NULL)
  10570. {
  10571. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10572. return ERR_INVALID_PARAMETER;
  10573. }
  10574. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10575. if (o == NULL)
  10576. {
  10577. return ERR_INVALID_PARAMETER;
  10578. }
  10579. Zero(&t, sizeof(t));
  10580. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10581. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10582. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10583. // RPC call
  10584. ret = ScGetLink(ps->Rpc, &t);
  10585. if (ret != ERR_NO_ERROR)
  10586. {
  10587. // An error has occured
  10588. CmdPrintError(c, ret);
  10589. FreeParamValueList(o);
  10590. return ret;
  10591. }
  10592. else
  10593. {
  10594. // Data change
  10595. t.ClientOption->UseEncrypt = true;
  10596. ret = ScSetLink(ps->Rpc, &t);
  10597. if (ret != ERR_NO_ERROR)
  10598. {
  10599. // An error has occured
  10600. CmdPrintError(c, ret);
  10601. FreeParamValueList(o);
  10602. return ret;
  10603. }
  10604. FreeRpcCreateLink(&t);
  10605. }
  10606. FreeParamValueList(o);
  10607. return 0;
  10608. }
  10609. // Disable encryption of communication at the time of the cascade connection
  10610. UINT PsCascadeEncryptDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10611. {
  10612. LIST *o;
  10613. PS *ps = (PS *)param;
  10614. UINT ret = 0;
  10615. RPC_CREATE_LINK t;
  10616. // Parameter list that can be specified
  10617. PARAM args[] =
  10618. {
  10619. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  10620. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10621. };
  10622. // If virtual HUB is not selected, it's an error
  10623. if (ps->HubName == NULL)
  10624. {
  10625. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10626. return ERR_INVALID_PARAMETER;
  10627. }
  10628. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10629. if (o == NULL)
  10630. {
  10631. return ERR_INVALID_PARAMETER;
  10632. }
  10633. Zero(&t, sizeof(t));
  10634. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10635. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10636. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10637. // RPC call
  10638. ret = ScGetLink(ps->Rpc, &t);
  10639. if (ret != ERR_NO_ERROR)
  10640. {
  10641. // An error has occured
  10642. CmdPrintError(c, ret);
  10643. FreeParamValueList(o);
  10644. return ret;
  10645. }
  10646. else
  10647. {
  10648. // Data change
  10649. t.ClientOption->UseEncrypt = false;
  10650. ret = ScSetLink(ps->Rpc, &t);
  10651. if (ret != ERR_NO_ERROR)
  10652. {
  10653. // An error has occured
  10654. CmdPrintError(c, ret);
  10655. FreeParamValueList(o);
  10656. return ret;
  10657. }
  10658. FreeRpcCreateLink(&t);
  10659. }
  10660. FreeParamValueList(o);
  10661. return 0;
  10662. }
  10663. // Enable data compression at the time of communication of the cascade connection
  10664. UINT PsCascadeCompressEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10665. {
  10666. LIST *o;
  10667. PS *ps = (PS *)param;
  10668. UINT ret = 0;
  10669. RPC_CREATE_LINK t;
  10670. // Parameter list that can be specified
  10671. PARAM args[] =
  10672. {
  10673. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  10674. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10675. };
  10676. // If virtual HUB is not selected, it's an error
  10677. if (ps->HubName == NULL)
  10678. {
  10679. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10680. return ERR_INVALID_PARAMETER;
  10681. }
  10682. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10683. if (o == NULL)
  10684. {
  10685. return ERR_INVALID_PARAMETER;
  10686. }
  10687. Zero(&t, sizeof(t));
  10688. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10689. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10690. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10691. // RPC call
  10692. ret = ScGetLink(ps->Rpc, &t);
  10693. if (ret != ERR_NO_ERROR)
  10694. {
  10695. // An error has occured
  10696. CmdPrintError(c, ret);
  10697. FreeParamValueList(o);
  10698. return ret;
  10699. }
  10700. else
  10701. {
  10702. // Data change
  10703. t.ClientOption->UseCompress = true;
  10704. ret = ScSetLink(ps->Rpc, &t);
  10705. if (ret != ERR_NO_ERROR)
  10706. {
  10707. // An error has occured
  10708. CmdPrintError(c, ret);
  10709. FreeParamValueList(o);
  10710. return ret;
  10711. }
  10712. FreeRpcCreateLink(&t);
  10713. }
  10714. FreeParamValueList(o);
  10715. return 0;
  10716. }
  10717. // Disable data compression at the time of communication of the cascade connection
  10718. UINT PsCascadeCompressDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10719. {
  10720. LIST *o;
  10721. PS *ps = (PS *)param;
  10722. UINT ret = 0;
  10723. RPC_CREATE_LINK t;
  10724. // Parameter list that can be specified
  10725. PARAM args[] =
  10726. {
  10727. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  10728. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10729. };
  10730. // If virtual HUB is not selected, it's an error
  10731. if (ps->HubName == NULL)
  10732. {
  10733. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10734. return ERR_INVALID_PARAMETER;
  10735. }
  10736. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10737. if (o == NULL)
  10738. {
  10739. return ERR_INVALID_PARAMETER;
  10740. }
  10741. Zero(&t, sizeof(t));
  10742. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10743. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10744. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10745. // RPC call
  10746. ret = ScGetLink(ps->Rpc, &t);
  10747. if (ret != ERR_NO_ERROR)
  10748. {
  10749. // An error has occured
  10750. CmdPrintError(c, ret);
  10751. FreeParamValueList(o);
  10752. return ret;
  10753. }
  10754. else
  10755. {
  10756. // Data change
  10757. t.ClientOption->UseCompress = false;
  10758. ret = ScSetLink(ps->Rpc, &t);
  10759. if (ret != ERR_NO_ERROR)
  10760. {
  10761. // An error has occured
  10762. CmdPrintError(c, ret);
  10763. FreeParamValueList(o);
  10764. return ret;
  10765. }
  10766. FreeRpcCreateLink(&t);
  10767. }
  10768. FreeParamValueList(o);
  10769. return 0;
  10770. }
  10771. // Set the cascade connection method to the TCP/IP direct connection mode
  10772. UINT PsCascadeProxyNone(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10773. {
  10774. LIST *o;
  10775. PS *ps = (PS *)param;
  10776. UINT ret = 0;
  10777. RPC_CREATE_LINK t;
  10778. // Parameter list that can be specified
  10779. PARAM args[] =
  10780. {
  10781. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  10782. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10783. };
  10784. // If virtual HUB is not selected, it's an error
  10785. if (ps->HubName == NULL)
  10786. {
  10787. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10788. return ERR_INVALID_PARAMETER;
  10789. }
  10790. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10791. if (o == NULL)
  10792. {
  10793. return ERR_INVALID_PARAMETER;
  10794. }
  10795. Zero(&t, sizeof(t));
  10796. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10797. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10798. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10799. // RPC call
  10800. ret = ScGetLink(ps->Rpc, &t);
  10801. if (ret != ERR_NO_ERROR)
  10802. {
  10803. // An error has occured
  10804. CmdPrintError(c, ret);
  10805. FreeParamValueList(o);
  10806. return ret;
  10807. }
  10808. else
  10809. {
  10810. // Data change
  10811. t.ClientOption->ProxyType = PROXY_DIRECT;
  10812. ret = ScSetLink(ps->Rpc, &t);
  10813. if (ret != ERR_NO_ERROR)
  10814. {
  10815. // An error has occured
  10816. CmdPrintError(c, ret);
  10817. FreeParamValueList(o);
  10818. return ret;
  10819. }
  10820. FreeRpcCreateLink(&t);
  10821. }
  10822. FreeParamValueList(o);
  10823. return 0;
  10824. }
  10825. // Set the cascade connection method as the mode via HTTP proxy server
  10826. UINT PsCascadeProxyHttp(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10827. {
  10828. LIST *o;
  10829. PS *ps = (PS *)param;
  10830. UINT ret = 0;
  10831. RPC_CREATE_LINK t;
  10832. // Parameter list that can be specified
  10833. PARAM args[] =
  10834. {
  10835. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  10836. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10837. {"SERVER", CmdPrompt, _UU("CMD_CascadeProxyHttp_Prompt_Server"), CmdEvalHostAndPort, NULL},
  10838. {"USERNAME", NULL, NULL, NULL, NULL},
  10839. {"PASSWORD", NULL, NULL, NULL, NULL},
  10840. };
  10841. // If virtual HUB is not selected, it's an error
  10842. if (ps->HubName == NULL)
  10843. {
  10844. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10845. return ERR_INVALID_PARAMETER;
  10846. }
  10847. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10848. if (o == NULL)
  10849. {
  10850. return ERR_INVALID_PARAMETER;
  10851. }
  10852. Zero(&t, sizeof(t));
  10853. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10854. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10855. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10856. // RPC call
  10857. ret = ScGetLink(ps->Rpc, &t);
  10858. if (ret != ERR_NO_ERROR)
  10859. {
  10860. // An error has occured
  10861. CmdPrintError(c, ret);
  10862. FreeParamValueList(o);
  10863. return ret;
  10864. }
  10865. else
  10866. {
  10867. char *host;
  10868. UINT port;
  10869. // Data change
  10870. if (ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 8080))
  10871. {
  10872. t.ClientOption->ProxyType = PROXY_HTTP;
  10873. StrCpy(t.ClientOption->ProxyName, sizeof(t.ClientOption->ProxyName), host);
  10874. t.ClientOption->ProxyPort = port;
  10875. StrCpy(t.ClientOption->ProxyUsername, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "USERNAME"));
  10876. StrCpy(t.ClientOption->ProxyPassword, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "PASSWORD"));
  10877. Free(host);
  10878. }
  10879. ret = ScSetLink(ps->Rpc, &t);
  10880. if (ret != ERR_NO_ERROR)
  10881. {
  10882. // An error has occured
  10883. CmdPrintError(c, ret);
  10884. FreeParamValueList(o);
  10885. return ret;
  10886. }
  10887. FreeRpcCreateLink(&t);
  10888. }
  10889. FreeParamValueList(o);
  10890. return 0;
  10891. }
  10892. // Set the cascade connection method as the mode via SOCKS proxy server
  10893. UINT PsCascadeProxySocks(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10894. {
  10895. LIST *o;
  10896. PS *ps = (PS *)param;
  10897. UINT ret = 0;
  10898. RPC_CREATE_LINK t;
  10899. // Parameter list that can be specified
  10900. PARAM args[] =
  10901. {
  10902. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  10903. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10904. {"SERVER", CmdPrompt, _UU("CMD_CascadeProxyHttp_Prompt_Server"), CmdEvalHostAndPort, NULL},
  10905. {"USERNAME", NULL, NULL, NULL, NULL},
  10906. {"PASSWORD", NULL, NULL, NULL, NULL},
  10907. };
  10908. // If virtual HUB is not selected, it's an error
  10909. if (ps->HubName == NULL)
  10910. {
  10911. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10912. return ERR_INVALID_PARAMETER;
  10913. }
  10914. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10915. if (o == NULL)
  10916. {
  10917. return ERR_INVALID_PARAMETER;
  10918. }
  10919. Zero(&t, sizeof(t));
  10920. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10921. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10922. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10923. // RPC call
  10924. ret = ScGetLink(ps->Rpc, &t);
  10925. if (ret != ERR_NO_ERROR)
  10926. {
  10927. // An error has occured
  10928. CmdPrintError(c, ret);
  10929. FreeParamValueList(o);
  10930. return ret;
  10931. }
  10932. else
  10933. {
  10934. char *host;
  10935. UINT port;
  10936. // Data change
  10937. if (ParseHostPort(GetParamStr(o, "SERVER"), &host, &port, 8080))
  10938. {
  10939. t.ClientOption->ProxyType = PROXY_SOCKS;
  10940. StrCpy(t.ClientOption->ProxyName, sizeof(t.ClientOption->ProxyName), host);
  10941. t.ClientOption->ProxyPort = port;
  10942. StrCpy(t.ClientOption->ProxyUsername, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "USERNAME"));
  10943. StrCpy(t.ClientOption->ProxyPassword, sizeof(t.ClientOption->ProxyName), GetParamStr(o, "PASSWORD"));
  10944. Free(host);
  10945. }
  10946. ret = ScSetLink(ps->Rpc, &t);
  10947. if (ret != ERR_NO_ERROR)
  10948. {
  10949. // An error has occured
  10950. CmdPrintError(c, ret);
  10951. FreeParamValueList(o);
  10952. return ret;
  10953. }
  10954. FreeRpcCreateLink(&t);
  10955. }
  10956. FreeParamValueList(o);
  10957. return 0;
  10958. }
  10959. // Enable the validation options for the server certificate of cascade connection
  10960. UINT PsCascadeServerCertEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  10961. {
  10962. LIST *o;
  10963. PS *ps = (PS *)param;
  10964. UINT ret = 0;
  10965. RPC_CREATE_LINK t;
  10966. // Parameter list that can be specified
  10967. PARAM args[] =
  10968. {
  10969. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  10970. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  10971. };
  10972. // If virtual HUB is not selected, it's an error
  10973. if (ps->HubName == NULL)
  10974. {
  10975. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  10976. return ERR_INVALID_PARAMETER;
  10977. }
  10978. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  10979. if (o == NULL)
  10980. {
  10981. return ERR_INVALID_PARAMETER;
  10982. }
  10983. Zero(&t, sizeof(t));
  10984. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  10985. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  10986. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  10987. // RPC call
  10988. ret = ScGetLink(ps->Rpc, &t);
  10989. if (ret != ERR_NO_ERROR)
  10990. {
  10991. // An error has occured
  10992. CmdPrintError(c, ret);
  10993. FreeParamValueList(o);
  10994. return ret;
  10995. }
  10996. else
  10997. {
  10998. // Data change
  10999. t.CheckServerCert = true;
  11000. ret = ScSetLink(ps->Rpc, &t);
  11001. if (ret != ERR_NO_ERROR)
  11002. {
  11003. // An error has occured
  11004. CmdPrintError(c, ret);
  11005. FreeParamValueList(o);
  11006. return ret;
  11007. }
  11008. FreeRpcCreateLink(&t);
  11009. }
  11010. FreeParamValueList(o);
  11011. return 0;
  11012. }
  11013. // Disable the validation options for the server certificate of cascade connection
  11014. UINT PsCascadeServerCertDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  11015. {
  11016. LIST *o;
  11017. PS *ps = (PS *)param;
  11018. UINT ret = 0;
  11019. RPC_CREATE_LINK t;
  11020. // Parameter list that can be specified
  11021. PARAM args[] =
  11022. {
  11023. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  11024. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  11025. };
  11026. // If virtual HUB is not selected, it's an error
  11027. if (ps->HubName == NULL)
  11028. {
  11029. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  11030. return ERR_INVALID_PARAMETER;
  11031. }
  11032. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  11033. if (o == NULL)
  11034. {
  11035. return ERR_INVALID_PARAMETER;
  11036. }
  11037. Zero(&t, sizeof(t));
  11038. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  11039. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  11040. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  11041. // RPC call
  11042. ret = ScGetLink(ps->Rpc, &t);
  11043. if (ret != ERR_NO_ERROR)
  11044. {
  11045. // An error has occured
  11046. CmdPrintError(c, ret);
  11047. FreeParamValueList(o);
  11048. return ret;
  11049. }
  11050. else
  11051. {
  11052. // Data change
  11053. t.CheckServerCert = false;
  11054. ret = ScSetLink(ps->Rpc, &t);
  11055. if (ret != ERR_NO_ERROR)
  11056. {
  11057. // An error has occured
  11058. CmdPrintError(c, ret);
  11059. FreeParamValueList(o);
  11060. return ret;
  11061. }
  11062. FreeRpcCreateLink(&t);
  11063. }
  11064. FreeParamValueList(o);
  11065. return 0;
  11066. }
  11067. // Server-specific certificate settings of cascade connection
  11068. UINT PsCascadeServerCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  11069. {
  11070. LIST *o;
  11071. PS *ps = (PS *)param;
  11072. UINT ret = 0;
  11073. RPC_CREATE_LINK t;
  11074. X *x;
  11075. // Parameter list that can be specified
  11076. PARAM args[] =
  11077. {
  11078. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  11079. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  11080. {"LOADCERT", CmdPrompt, _UU("CMD_LOADCERTPATH"), CmdEvalIsFile, NULL},
  11081. };
  11082. // If virtual HUB is not selected, it's an error
  11083. if (ps->HubName == NULL)
  11084. {
  11085. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  11086. return ERR_INVALID_PARAMETER;
  11087. }
  11088. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  11089. if (o == NULL)
  11090. {
  11091. return ERR_INVALID_PARAMETER;
  11092. }
  11093. x = FileToXW(GetParamUniStr(o, "LOADCERT"));
  11094. if (x == NULL)
  11095. {
  11096. FreeParamValueList(o);
  11097. c->Write(c, _UU("CMD_LOADCERT_FAILED"));
  11098. return ERR_INTERNAL_ERROR;
  11099. }
  11100. Zero(&t, sizeof(t));
  11101. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  11102. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  11103. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  11104. // RPC call
  11105. ret = ScGetLink(ps->Rpc, &t);
  11106. if (ret != ERR_NO_ERROR)
  11107. {
  11108. // An error has occured
  11109. CmdPrintError(c, ret);
  11110. FreeParamValueList(o);
  11111. FreeX(x);
  11112. return ret;
  11113. }
  11114. else
  11115. {
  11116. // Data change
  11117. if (t.ServerCert != NULL)
  11118. {
  11119. FreeX(t.ServerCert);
  11120. }
  11121. t.ServerCert = x;
  11122. ret = ScSetLink(ps->Rpc, &t);
  11123. if (ret != ERR_NO_ERROR)
  11124. {
  11125. // An error has occured
  11126. CmdPrintError(c, ret);
  11127. FreeParamValueList(o);
  11128. return ret;
  11129. }
  11130. FreeRpcCreateLink(&t);
  11131. }
  11132. FreeParamValueList(o);
  11133. return 0;
  11134. }
  11135. // Delete the server-specific certificate of cascade connection
  11136. UINT PsCascadeServerCertDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  11137. {
  11138. LIST *o;
  11139. PS *ps = (PS *)param;
  11140. UINT ret = 0;
  11141. RPC_CREATE_LINK t;
  11142. // Parameter list that can be specified
  11143. PARAM args[] =
  11144. {
  11145. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  11146. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  11147. };
  11148. // If virtual HUB is not selected, it's an error
  11149. if (ps->HubName == NULL)
  11150. {
  11151. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  11152. return ERR_INVALID_PARAMETER;
  11153. }
  11154. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  11155. if (o == NULL)
  11156. {
  11157. return ERR_INVALID_PARAMETER;
  11158. }
  11159. Zero(&t, sizeof(t));
  11160. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  11161. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  11162. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  11163. // RPC call
  11164. ret = ScGetLink(ps->Rpc, &t);
  11165. if (ret != ERR_NO_ERROR)
  11166. {
  11167. // An error has occured
  11168. CmdPrintError(c, ret);
  11169. FreeParamValueList(o);
  11170. return ret;
  11171. }
  11172. else
  11173. {
  11174. // Data change
  11175. if (t.ServerCert != NULL)
  11176. {
  11177. FreeX(t.ServerCert);
  11178. }
  11179. t.ServerCert = NULL;
  11180. ret = ScSetLink(ps->Rpc, &t);
  11181. if (ret != ERR_NO_ERROR)
  11182. {
  11183. // An error has occured
  11184. CmdPrintError(c, ret);
  11185. FreeParamValueList(o);
  11186. return ret;
  11187. }
  11188. FreeRpcCreateLink(&t);
  11189. }
  11190. FreeParamValueList(o);
  11191. return 0;
  11192. }
  11193. // Get the server-specific certificate of cascade connection
  11194. UINT PsCascadeServerCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  11195. {
  11196. LIST *o;
  11197. PS *ps = (PS *)param;
  11198. UINT ret = 0;
  11199. RPC_CREATE_LINK t;
  11200. // Parameter list that can be specified
  11201. PARAM args[] =
  11202. {
  11203. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  11204. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  11205. {"SAVECERT", CmdPrompt, _UU("CMD_SAVECERTPATH"), CmdEvalNotEmpty, NULL},
  11206. };
  11207. // If virtual HUB is not selected, it's an error
  11208. if (ps->HubName == NULL)
  11209. {
  11210. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  11211. return ERR_INVALID_PARAMETER;
  11212. }
  11213. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  11214. if (o == NULL)
  11215. {
  11216. return ERR_INVALID_PARAMETER;
  11217. }
  11218. Zero(&t, sizeof(t));
  11219. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  11220. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  11221. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  11222. // RPC call
  11223. ret = ScGetLink(ps->Rpc, &t);
  11224. if (ret != ERR_NO_ERROR)
  11225. {
  11226. // An error has occured
  11227. CmdPrintError(c, ret);
  11228. FreeParamValueList(o);
  11229. return ret;
  11230. }
  11231. else
  11232. {
  11233. // Save the certificate
  11234. if (t.ServerCert == NULL)
  11235. {
  11236. c->Write(c, _UU("CMD_CERT_NOT_EXISTS"));
  11237. ret = ERR_INTERNAL_ERROR;
  11238. }
  11239. else
  11240. {
  11241. if (XToFileW(t.ServerCert, GetParamUniStr(o, "SAVECERT"), true) == false)
  11242. {
  11243. c->Write(c, _UU("CMD_SAVECERT_FAILED"));
  11244. ret = ERR_INTERNAL_ERROR;
  11245. }
  11246. }
  11247. FreeRpcCreateLink(&t);
  11248. }
  11249. FreeParamValueList(o);
  11250. return ret;
  11251. }
  11252. // Set the advanced settings of the cascade connection
  11253. UINT PsCascadeDetailSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  11254. {
  11255. LIST *o;
  11256. PS *ps = (PS *)param;
  11257. UINT ret = 0;
  11258. RPC_CREATE_LINK t;
  11259. CMD_EVAL_MIN_MAX mm_maxtcp =
  11260. {
  11261. "CMD_CascadeDetailSet_Eval_MaxTcp", 1, 32
  11262. };
  11263. CMD_EVAL_MIN_MAX mm_interval =
  11264. {
  11265. "CMD_CascadeDetailSet_Eval_Interval", 1, 4294967295UL
  11266. };
  11267. // Parameter list that can be specified
  11268. PARAM args[] =
  11269. {
  11270. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  11271. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  11272. {"MAXTCP", CmdPrompt, _UU("CMD_CascadeDetailSet_Prompt_MaxTcp"), CmdEvalMinMax, &mm_maxtcp},
  11273. {"INTERVAL", CmdPrompt, _UU("CMD_CascadeDetailSet_Prompt_Interval"), CmdEvalMinMax, &mm_interval},
  11274. {"TTL", CmdPrompt, _UU("CMD_CascadeDetailSet_Prompt_TTL"), NULL, NULL},
  11275. {"HALF", CmdPrompt, _UU("CMD_CascadeDetailSet_Prompt_HALF"), NULL, NULL},
  11276. {"NOQOS", CmdPrompt, _UU("CMD_AccountDetailSet_Prompt_NOQOS"), NULL, NULL},
  11277. };
  11278. // If virtual HUB is not selected, it's an error
  11279. if (ps->HubName == NULL)
  11280. {
  11281. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  11282. return ERR_INVALID_PARAMETER;
  11283. }
  11284. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  11285. if (o == NULL)
  11286. {
  11287. return ERR_INVALID_PARAMETER;
  11288. }
  11289. Zero(&t, sizeof(t));
  11290. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  11291. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  11292. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  11293. // RPC call
  11294. ret = ScGetLink(ps->Rpc, &t);
  11295. if (ret != ERR_NO_ERROR)
  11296. {
  11297. // An error has occured
  11298. CmdPrintError(c, ret);
  11299. FreeParamValueList(o);
  11300. return ret;
  11301. }
  11302. else
  11303. {
  11304. // Data change
  11305. t.ClientOption->MaxConnection = GetParamInt(o, "MAXTCP");
  11306. t.ClientOption->AdditionalConnectionInterval = GetParamInt(o, "INTERVAL");
  11307. t.ClientOption->ConnectionDisconnectSpan = GetParamInt(o, "TTL");
  11308. t.ClientOption->HalfConnection = GetParamYes(o, "HALF");
  11309. t.ClientOption->DisableQoS = GetParamYes(o, "NOQOS");
  11310. ret = ScSetLink(ps->Rpc, &t);
  11311. if (ret != ERR_NO_ERROR)
  11312. {
  11313. // An error has occured
  11314. CmdPrintError(c, ret);
  11315. FreeParamValueList(o);
  11316. return ret;
  11317. }
  11318. FreeRpcCreateLink(&t);
  11319. }
  11320. FreeParamValueList(o);
  11321. return 0;
  11322. }
  11323. // Show a security policy
  11324. void PrintPolicy(CONSOLE *c, POLICY *pol, bool cascade_mode)
  11325. {
  11326. UINT i;
  11327. CT *ct;
  11328. PACK *p;
  11329. // Validate arguments
  11330. if (c == NULL || pol == NULL)
  11331. {
  11332. return;
  11333. }
  11334. ct = CtNew();
  11335. CtInsertColumn(ct, _UU("CMD_PolicyList_Column_1"), false);
  11336. CtInsertColumn(ct, _UU("CMD_PolicyList_Column_2"), false);
  11337. CtInsertColumn(ct, _UU("CMD_PolicyList_Column_3"), false);
  11338. p = NewPack();
  11339. OutRpcPolicy(p, pol);
  11340. // Show the list of all policies
  11341. for (i = 0; i < PolicyNum();i++)
  11342. {
  11343. char name[64];
  11344. wchar_t *tmp;
  11345. if (cascade_mode == false || PolicyIsSupportedForCascade(i))
  11346. {
  11347. wchar_t value_str[256];
  11348. UINT value;
  11349. char tmp2[256];
  11350. Format(tmp2, sizeof(tmp2), "policy:%s", PolicyIdToStr(i));
  11351. value = PackGetInt(p, tmp2);
  11352. tmp = CopyStrToUni(PolicyIdToStr(i));
  11353. FormatPolicyValue(value_str, sizeof(value_str),
  11354. i, value);
  11355. Format(name, sizeof(name), "POL_%u", i);
  11356. CtInsert(ct, tmp, _UU(name), value_str);
  11357. Free(tmp);
  11358. }
  11359. }
  11360. FreePack(p);
  11361. CtFree(ct, c);
  11362. }
  11363. // Show the security policy list
  11364. void PrintPolicyList(CONSOLE *c, char *name)
  11365. {
  11366. UINT id;
  11367. // Validate arguments
  11368. if (c == NULL)
  11369. {
  11370. return;
  11371. }
  11372. if (IsEmptyStr(name))
  11373. {
  11374. name = NULL;
  11375. }
  11376. if (name != NULL)
  11377. {
  11378. id = PolicyStrToId(name);
  11379. if (id == INFINITE)
  11380. {
  11381. // Invalid ID
  11382. c->Write(c, _UU("CMD_PolicyList_Invalid_Name"));
  11383. }
  11384. else
  11385. {
  11386. wchar_t tmp[MAX_SIZE];
  11387. wchar_t tmp2[MAX_SIZE];
  11388. char name1[64], name2[64];
  11389. wchar_t *title, *descript;
  11390. wchar_t policy_name[MAX_SIZE];
  11391. Format(name1, sizeof(name1), "POL_%u", id);
  11392. Format(name2, sizeof(name2), "POL_EX_%u", id);
  11393. title = _UU(name1);
  11394. descript = _UU(name2);
  11395. StrToUni(policy_name, sizeof(policy_name), PolicyIdToStr(id));
  11396. // Policy name
  11397. c->Write(c, _UU("CMD_PolicyList_Help_1"));
  11398. UniFormat(tmp2, sizeof(tmp2), L" %s", policy_name);
  11399. c->Write(c, tmp2);
  11400. c->Write(c, L"");
  11401. // Simple description of the policy
  11402. c->Write(c, _UU("CMD_PolicyList_Help_2"));
  11403. UniFormat(tmp2, sizeof(tmp2), L" %s", title);
  11404. c->Write(c, tmp2);
  11405. c->Write(c, L"");
  11406. // Range of the value that can be set
  11407. GetPolicyValueRangeStr(tmp, sizeof(tmp), id);
  11408. c->Write(c, _UU("CMD_PolicyList_Help_3"));
  11409. UniFormat(tmp2, sizeof(tmp2), L" %s", tmp);
  11410. c->Write(c, tmp2);
  11411. c->Write(c, L"");
  11412. // Default value
  11413. FormatPolicyValue(tmp, sizeof(tmp), id, GetPolicyItem(id)->DefaultValue);
  11414. c->Write(c, _UU("CMD_PolicyList_Help_4"));
  11415. UniFormat(tmp2, sizeof(tmp2), L" %s", tmp);
  11416. c->Write(c, tmp2);
  11417. c->Write(c, L"");
  11418. // Detailed description of the policy
  11419. c->Write(c, _UU("CMD_PolicyList_Help_5"));
  11420. c->Write(c, descript);
  11421. c->Write(c, L"");
  11422. }
  11423. }
  11424. else
  11425. {
  11426. UINT i;
  11427. CT *ct = CtNew();
  11428. CtInsertColumn(ct, _UU("CMD_PolicyList_Column_1"), false);
  11429. CtInsertColumn(ct, _UU("CMD_PolicyList_Column_2"), false);
  11430. // Show the list of all policies
  11431. for (i = 0; i < PolicyNum();i++)
  11432. {
  11433. char name[64];
  11434. wchar_t *tmp;
  11435. tmp = CopyStrToUni(PolicyIdToStr(i));
  11436. Format(name, sizeof(name), "POL_%u", i);
  11437. CtInsert(ct, tmp, _UU(name));
  11438. Free(tmp);
  11439. }
  11440. CtFree(ct, c);
  11441. }
  11442. }
  11443. // Editing the contents of the policy
  11444. bool EditPolicy(CONSOLE *c, POLICY *pol, char *name, char *value, bool cascade_mode)
  11445. {
  11446. PACK *p;
  11447. ELEMENT *e;
  11448. POLICY_ITEM *item;
  11449. UINT id;
  11450. wchar_t tmp[MAX_SIZE];
  11451. wchar_t tmp2[MAX_SIZE];
  11452. char pack_name[128];
  11453. // Validate arguments
  11454. if (c == NULL || pol == NULL || name == NULL || value == NULL)
  11455. {
  11456. return false;
  11457. }
  11458. p = NewPack();
  11459. OutRpcPolicy(p, pol);
  11460. Format(pack_name, sizeof(pack_name), "policy:%s", PolicyIdToStr(PolicyStrToId(name)));
  11461. if ((e = GetElement(p, pack_name, VALUE_INT)) == NULL || (id = PolicyStrToId(name)) == INFINITE)
  11462. {
  11463. UniFormat(tmp, sizeof(tmp), _UU("CMD_CascadePolicySet_Invalid_Name"), name);
  11464. c->Write(c, tmp);
  11465. FreePack(p);
  11466. return false;
  11467. }
  11468. if (cascade_mode && (PolicyIsSupportedForCascade(id) == false))
  11469. {
  11470. UniFormat(tmp, sizeof(tmp), _UU("CMD_CascadePolicySet_Invalid_Name_For_Cadcade"), name);
  11471. c->Write(c, tmp);
  11472. FreePack(p);
  11473. return false;
  11474. }
  11475. item = GetPolicyItem(id);
  11476. if (item->TypeInt == false)
  11477. {
  11478. // bool type
  11479. e->values[0]->IntValue = (
  11480. StartWith(value, "y") || StartWith(value, "t") ||
  11481. ToInt(value) != 0) ? 1 : 0;
  11482. }
  11483. else
  11484. {
  11485. UINT n = ToInt(value);
  11486. bool b = true;
  11487. // int type
  11488. GetPolicyValueRangeStr(tmp, sizeof(tmp), id);
  11489. if (item->AllowZero == false)
  11490. {
  11491. if (n == 0)
  11492. {
  11493. b = false;
  11494. }
  11495. }
  11496. if (n != 0 && (n < item->MinValue || n > item->MaxValue))
  11497. {
  11498. b = false;
  11499. }
  11500. if (b == false)
  11501. {
  11502. UniFormat(tmp2, sizeof(tmp2), _UU("CMD_CascadePolicySet_Invalid_Range"), PolicyIdToStr(id), tmp);
  11503. c->Write(c, tmp2);
  11504. FreePack(p);
  11505. return false;
  11506. }
  11507. e->values[0]->IntValue = n;
  11508. }
  11509. Zero(pol, sizeof(POLICY));
  11510. InRpcPolicy(pol, p);
  11511. FreePack(p);
  11512. return true;
  11513. }
  11514. // Show the list of the type of security policy and possible values
  11515. UINT PsPolicyList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  11516. {
  11517. LIST *o;
  11518. PARAM args[] =
  11519. {
  11520. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  11521. {"[name]", NULL, NULL, NULL, NULL}
  11522. };
  11523. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  11524. if (o == NULL)
  11525. {
  11526. return ERR_INVALID_PARAMETER;
  11527. }
  11528. PrintPolicyList(c, GetParamStr(o, "[name]"));
  11529. FreeParamValueList(o);
  11530. return ERR_NO_ERROR;
  11531. }
  11532. // Set the security policy of the cascade session
  11533. UINT PsCascadePolicySet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  11534. {
  11535. LIST *o;
  11536. PS *ps = (PS *)param;
  11537. UINT ret = 0;
  11538. RPC_CREATE_LINK t;
  11539. // Parameter list that can be specified
  11540. PARAM args[] =
  11541. {
  11542. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  11543. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  11544. {"NAME", CmdPrompt, _UU("CMD_CascadePolicySet_PROMPT_POLNAME"), CmdEvalNotEmpty, NULL},
  11545. {"VALUE", CmdPrompt, _UU("CMD_CascadePolicySet_PROMPT_POLVALUE"), CmdEvalNotEmpty, NULL},
  11546. };
  11547. // If virtual HUB is not selected, it's an error
  11548. if (ps->HubName == NULL)
  11549. {
  11550. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  11551. return ERR_INVALID_PARAMETER;
  11552. }
  11553. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  11554. if (o == NULL)
  11555. {
  11556. return ERR_INVALID_PARAMETER;
  11557. }
  11558. Zero(&t, sizeof(t));
  11559. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  11560. t.ClientOption = ZeroMalloc(sizeof(CLIENT_OPTION));
  11561. UniStrCpy(t.ClientOption->AccountName, sizeof(t.ClientOption->AccountName), GetParamUniStr(o, "[name]"));
  11562. // RPC call
  11563. ret = ScGetLink(ps->Rpc, &t);
  11564. if (ret != ERR_NO_ERROR)
  11565. {
  11566. // An error has occured
  11567. CmdPrintError(c, ret);
  11568. FreeParamValueList(o);
  11569. return ret;
  11570. }
  11571. else
  11572. {
  11573. if (EditPolicy(c, &t.Policy, GetParamStr(o, "NAME"), GetParamStr(o, "VALUE"), true) == false)
  11574. {
  11575. // An error has occured
  11576. FreeRpcCreateLink(&t);
  11577. FreeParamValueList(o);
  11578. return ERR_INTERNAL_ERROR;
  11579. }
  11580. ret = ScSetLink(ps->Rpc, &t);
  11581. if (ret != ERR_NO_ERROR)
  11582. {
  11583. // An error has occured
  11584. CmdPrintError(c, ret);
  11585. FreeParamValueList(o);
  11586. return ret;
  11587. }
  11588. FreeRpcCreateLink(&t);
  11589. }
  11590. FreeParamValueList(o);
  11591. return 0;
  11592. }
  11593. // Display the status information of the session
  11594. void CmdPrintStatusToListView(CT *ct, RPC_CLIENT_GET_CONNECTION_STATUS *s)
  11595. {
  11596. CmdPrintStatusToListViewEx(ct, s, false);
  11597. }
  11598. void CmdPrintStatusToListViewEx(CT *ct, RPC_CLIENT_GET_CONNECTION_STATUS *s, bool server_mode)
  11599. {
  11600. wchar_t tmp[MAX_SIZE];
  11601. char str[MAX_SIZE];
  11602. char vv[128];
  11603. // Validate arguments
  11604. if (s == NULL)
  11605. {
  11606. return;
  11607. }
  11608. if (server_mode == false)
  11609. {
  11610. CtInsert(ct, _UU("CM_ST_ACCOUNT_NAME"), s->AccountName);
  11611. if (s->Connected == false)
  11612. {
  11613. wchar_t *st = _UU("CM_ST_CONNECTED_FALSE");
  11614. switch (s->SessionStatus)
  11615. {
  11616. case CLIENT_STATUS_CONNECTING:
  11617. st = _UU("CM_ST_CONNECTING");
  11618. break;
  11619. case CLIENT_STATUS_NEGOTIATION:
  11620. st = _UU("CM_ST_NEGOTIATION");
  11621. break;
  11622. case CLIENT_STATUS_AUTH:
  11623. st = _UU("CM_ST_AUTH");
  11624. break;
  11625. case CLIENT_STATUS_ESTABLISHED:
  11626. st = _UU("CM_ST_ESTABLISHED");
  11627. break;
  11628. case CLIENT_STATUS_RETRY:
  11629. st = _UU("CM_ST_RETRY");
  11630. break;
  11631. case CLIENT_STATUS_IDLE:
  11632. st = _UU("CM_ST_IDLE");
  11633. break;
  11634. }
  11635. CtInsert(ct, _UU("CM_ST_CONNECTED"), st);
  11636. }
  11637. else
  11638. {
  11639. CtInsert(ct, _UU("CM_ST_CONNECTED"), _UU("CM_ST_CONNECTED_TRUE"));
  11640. }
  11641. }
  11642. if (s->Connected)
  11643. {
  11644. if (s->VLanId == 0)
  11645. {
  11646. UniStrCpy(tmp, sizeof(tmp), _UU("CM_ST_NO_VLAN"));
  11647. }
  11648. else
  11649. {
  11650. UniToStru(tmp, s->VLanId);
  11651. }
  11652. CtInsert(ct, _UU("CM_ST_VLAN_ID"), tmp);
  11653. if (server_mode == false)
  11654. {
  11655. StrToUni(tmp, sizeof(tmp), s->ServerName);
  11656. CtInsert(ct, _UU("CM_ST_SERVER_NAME"), tmp);
  11657. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_PORT_TCP"), s->ServerPort);
  11658. CtInsert(ct, _UU("CM_ST_SERVER_PORT"), tmp);
  11659. }
  11660. StrToUni(tmp, sizeof(tmp), s->ServerProductName);
  11661. CtInsert(ct, _UU("CM_ST_SERVER_P_NAME"), tmp);
  11662. UniFormat(tmp, sizeof(tmp), L"%u.%02u", s->ServerProductVer / 100, s->ServerProductVer % 100);
  11663. CtInsert(ct, _UU("CM_ST_SERVER_P_VER"), tmp);
  11664. UniFormat(tmp, sizeof(tmp), L"Build %u", s->ServerProductBuild);
  11665. CtInsert(ct, _UU("CM_ST_SERVER_P_BUILD"), tmp);
  11666. }
  11667. GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(s->StartTime), NULL);
  11668. CtInsert(ct, _UU("CM_ST_START_TIME"), tmp);
  11669. GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(s->FirstConnectionEstablisiedTime), NULL);
  11670. CtInsert(ct, _UU("CM_ST_FIRST_ESTAB_TIME"), s->FirstConnectionEstablisiedTime == 0 ? _UU("CM_ST_NONE") : tmp);
  11671. if (s->Connected)
  11672. {
  11673. GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(s->CurrentConnectionEstablishTime), NULL);
  11674. CtInsert(ct, _UU("CM_ST_CURR_ESTAB_TIME"), tmp);
  11675. }
  11676. if (server_mode == false)
  11677. {
  11678. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_STR"), s->NumConnectionsEatablished);
  11679. CtInsert(ct, _UU("CM_ST_NUM_ESTABLISHED"), tmp);
  11680. }
  11681. if (s->Connected)
  11682. {
  11683. CtInsert(ct, _UU("CM_ST_HALF_CONNECTION"), s->HalfConnection ? _UU("CM_ST_HALF_TRUE") : _UU("CM_ST_HALF_FALSE"));
  11684. CtInsert(ct, _UU("CM_ST_QOS"), s->QoS ? _UU("CM_ST_QOS_TRUE") : _UU("CM_ST_QOS_FALSE"));
  11685. UniFormat(tmp, sizeof(tmp), L"%u", s->NumTcpConnections);
  11686. CtInsert(ct, _UU("CM_ST_NUM_TCP"), tmp);
  11687. if (s->HalfConnection)
  11688. {
  11689. UniFormat(tmp, sizeof(tmp), L"%u", s->NumTcpConnectionsUpload);
  11690. CtInsert(ct, _UU("CM_ST_NUM_TCP_UPLOAD"), tmp);
  11691. UniFormat(tmp, sizeof(tmp), L"%u", s->NumTcpConnectionsDownload);
  11692. CtInsert(ct, _UU("CM_ST_NUM_TCP_DOWNLOAD"), tmp);
  11693. }
  11694. UniFormat(tmp, sizeof(tmp), L"%u", s->MaxTcpConnections);
  11695. CtInsert(ct, _UU("CM_ST_MAX_TCP"), tmp);
  11696. if (s->UseEncrypt == false)
  11697. {
  11698. UniStrCpy(tmp, sizeof(tmp), _UU("CM_ST_USE_ENCRYPT_FALSE"));
  11699. }
  11700. else
  11701. {
  11702. if (StrLen(s->CipherName) != 0)
  11703. {
  11704. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_USE_ENCRYPT_TRUE"), s->CipherName);
  11705. }
  11706. else
  11707. {
  11708. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_USE_ENCRYPT_TRUE2"));
  11709. }
  11710. }
  11711. CtInsert(ct, _UU("CM_ST_USE_ENCRYPT"), tmp);
  11712. if (s->UseCompress)
  11713. {
  11714. UINT percent = 0;
  11715. if ((s->TotalRecvSize + s->TotalSendSize) > 0)
  11716. {
  11717. percent = (UINT)((UINT64)100 - (UINT64)(s->TotalRecvSizeReal + s->TotalSendSizeReal) * (UINT64)100 /
  11718. (s->TotalRecvSize + s->TotalSendSize));
  11719. percent = MAKESURE(percent, 0, 100);
  11720. }
  11721. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_COMPRESS_TRUE"), percent);
  11722. }
  11723. else
  11724. {
  11725. UniStrCpy(tmp, sizeof(tmp), _UU("CM_ST_COMPRESS_FALSE"));
  11726. }
  11727. CtInsert(ct, _UU("CM_ST_USE_COMPRESS"), tmp);
  11728. if (IsEmptyStr(s->UnderlayProtocol) == false)
  11729. {
  11730. StrToUni(tmp, sizeof(tmp), s->UnderlayProtocol);
  11731. CtInsert(ct, _UU("CM_ST_UNDERLAY_PROTOCOL"), tmp);
  11732. }
  11733. CtInsert(ct, _UU("CM_ST_UDP_ACCEL_ENABLED"), (s->IsUdpAccelerationEnabled ? _UU("CM_ST_YES") : _UU("CM_ST_NO")));
  11734. CtInsert(ct, _UU("CM_ST_UDP_ACCEL_USING"), (s->IsUsingUdpAcceleration ? _UU("CM_ST_YES") : _UU("CM_ST_NO")));
  11735. StrToUni(tmp, sizeof(tmp), s->SessionName);
  11736. CtInsert(ct, _UU("CM_ST_SESSION_NAME"), tmp);
  11737. StrToUni(tmp, sizeof(tmp), s->ConnectionName);
  11738. if (UniStrCmpi(tmp, L"INITING") != 0)
  11739. {
  11740. CtInsert(ct, _UU("CM_ST_CONNECTION_NAME"), tmp);
  11741. }
  11742. BinToStr(str, sizeof(str), s->SessionKey, sizeof(s->SessionKey));
  11743. StrToUni(tmp, sizeof(tmp), str);
  11744. CtInsert(ct, _UU("CM_ST_SESSION_KEY"), tmp);
  11745. CtInsert(ct, _UU("CM_ST_BRIDGE_MODE"), s->IsBridgeMode ? _UU("CM_ST_YES") : _UU("CM_ST_NO"));
  11746. CtInsert(ct, _UU("CM_ST_MONITOR_MODE"), s->IsMonitorMode ? _UU("CM_ST_YES") : _UU("CM_ST_NO"));
  11747. ToStr3(vv, sizeof(vv), s->TotalSendSize);
  11748. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);
  11749. CtInsert(ct, _UU("CM_ST_SEND_SIZE"), tmp);
  11750. ToStr3(vv, sizeof(vv), s->TotalRecvSize);
  11751. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);
  11752. CtInsert(ct, _UU("CM_ST_RECV_SIZE"), tmp);
  11753. ToStr3(vv, sizeof(vv), s->Traffic.Send.UnicastCount);
  11754. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_PACKET_STR"), vv);
  11755. CtInsert(ct, _UU("CM_ST_SEND_UCAST_NUM"), tmp);
  11756. ToStr3(vv, sizeof(vv), s->Traffic.Send.UnicastBytes);
  11757. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);
  11758. CtInsert(ct, _UU("CM_ST_SEND_UCAST_SIZE"), tmp);
  11759. ToStr3(vv, sizeof(vv), s->Traffic.Send.BroadcastCount);
  11760. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_PACKET_STR"), vv);
  11761. CtInsert(ct, _UU("CM_ST_SEND_BCAST_NUM"), tmp);
  11762. ToStr3(vv, sizeof(vv), s->Traffic.Send.BroadcastBytes);
  11763. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);
  11764. CtInsert(ct, _UU("CM_ST_SEND_BCAST_SIZE"), tmp);
  11765. ToStr3(vv, sizeof(vv), s->Traffic.Recv.UnicastCount);
  11766. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_PACKET_STR"), vv);
  11767. CtInsert(ct, _UU("CM_ST_RECV_UCAST_NUM"), tmp);
  11768. ToStr3(vv, sizeof(vv), s->Traffic.Recv.UnicastBytes);
  11769. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);
  11770. CtInsert(ct, _UU("CM_ST_RECV_UCAST_SIZE"), tmp);
  11771. ToStr3(vv, sizeof(vv), s->Traffic.Recv.BroadcastCount);
  11772. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_NUM_PACKET_STR"), vv);
  11773. CtInsert(ct, _UU("CM_ST_RECV_BCAST_NUM"), tmp);
  11774. ToStr3(vv, sizeof(vv), s->Traffic.Recv.BroadcastBytes);
  11775. UniFormat(tmp, sizeof(tmp), _UU("CM_ST_SIZE_BYTE_STR"), vv);
  11776. CtInsert(ct, _UU("CM_ST_RECV_BCAST_SIZE"), tmp);
  11777. }
  11778. }
  11779. // Get the current state of the cascade connection
  11780. UINT PsCascadeStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  11781. {
  11782. LIST *o;
  11783. PS *ps = (PS *)param;
  11784. UINT ret = 0;
  11785. RPC_LINK_STATUS t;
  11786. // Parameter list that can be specified
  11787. PARAM args[] =
  11788. {
  11789. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  11790. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  11791. };
  11792. // If virtual HUB is not selected, it's an error
  11793. if (ps->HubName == NULL)
  11794. {
  11795. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  11796. return ERR_INVALID_PARAMETER;
  11797. }
  11798. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  11799. if (o == NULL)
  11800. {
  11801. return ERR_INVALID_PARAMETER;
  11802. }
  11803. Zero(&t, sizeof(t));
  11804. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  11805. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  11806. // RPC call
  11807. ret = ScGetLinkStatus(ps->Rpc, &t);
  11808. if (ret != ERR_NO_ERROR)
  11809. {
  11810. // An error has occured
  11811. CmdPrintError(c, ret);
  11812. FreeParamValueList(o);
  11813. return ret;
  11814. }
  11815. else
  11816. {
  11817. // Get the cascade connection state
  11818. CT *ct = CtNewStandard();
  11819. CmdPrintStatusToListView(ct, &t.Status);
  11820. CtFree(ct, c);
  11821. FreeRpcLinkStatus(&t);
  11822. }
  11823. FreeParamValueList(o);
  11824. return 0;
  11825. }
  11826. // Rename the cascade connection
  11827. UINT PsCascadeRename(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  11828. {
  11829. LIST *o;
  11830. PS *ps = (PS *)param;
  11831. UINT ret = 0;
  11832. RPC_RENAME_LINK t;
  11833. // Parameter list that can be specified
  11834. PARAM args[] =
  11835. {
  11836. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  11837. {"[name]", CmdPrompt, _UU("CMD_CascadeRename_PROMPT_OLD"), CmdEvalNotEmpty, NULL},
  11838. {"NEW", CmdPrompt, _UU("CMD_CascadeRename_PROMPT_NEW"), CmdEvalNotEmpty, NULL},
  11839. };
  11840. // If virtual HUB is not selected, it's an error
  11841. if (ps->HubName == NULL)
  11842. {
  11843. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  11844. return ERR_INVALID_PARAMETER;
  11845. }
  11846. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  11847. if (o == NULL)
  11848. {
  11849. return ERR_INVALID_PARAMETER;
  11850. }
  11851. Zero(&t, sizeof(t));
  11852. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  11853. UniStrCpy(t.NewAccountName, sizeof(t.NewAccountName), GetParamUniStr(o, "NEW"));
  11854. UniStrCpy(t.OldAccountName, sizeof(t.OldAccountName), GetParamUniStr(o, "[name]"));
  11855. // RPC call
  11856. ret = ScRenameLink(ps->Rpc, &t);
  11857. if (ret != ERR_NO_ERROR)
  11858. {
  11859. // An error has occured
  11860. CmdPrintError(c, ret);
  11861. FreeParamValueList(o);
  11862. return ret;
  11863. }
  11864. FreeParamValueList(o);
  11865. return 0;
  11866. }
  11867. // Set the cascade connection to on-line state
  11868. UINT PsCascadeOnline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  11869. {
  11870. LIST *o;
  11871. PS *ps = (PS *)param;
  11872. UINT ret = 0;
  11873. RPC_LINK t;
  11874. // Parameter list that can be specified
  11875. PARAM args[] =
  11876. {
  11877. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  11878. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  11879. };
  11880. // If virtual HUB is not selected, it's an error
  11881. if (ps->HubName == NULL)
  11882. {
  11883. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  11884. return ERR_INVALID_PARAMETER;
  11885. }
  11886. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  11887. if (o == NULL)
  11888. {
  11889. return ERR_INVALID_PARAMETER;
  11890. }
  11891. Zero(&t, sizeof(t));
  11892. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  11893. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  11894. // RPC call
  11895. ret = ScSetLinkOnline(ps->Rpc, &t);
  11896. if (ret != ERR_NO_ERROR)
  11897. {
  11898. // An error has occured
  11899. CmdPrintError(c, ret);
  11900. FreeParamValueList(o);
  11901. return ret;
  11902. }
  11903. FreeParamValueList(o);
  11904. return 0;
  11905. }
  11906. // Set the cascade connection to the off-line state
  11907. UINT PsCascadeOffline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  11908. {
  11909. LIST *o;
  11910. PS *ps = (PS *)param;
  11911. UINT ret = 0;
  11912. RPC_LINK t;
  11913. // Parameter list that can be specified
  11914. PARAM args[] =
  11915. {
  11916. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  11917. {"[name]", CmdPrompt, _UU("CMD_CascadeCreate_Prompt_Name"), CmdEvalNotEmpty, NULL},
  11918. };
  11919. // If virtual HUB is not selected, it's an error
  11920. if (ps->HubName == NULL)
  11921. {
  11922. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  11923. return ERR_INVALID_PARAMETER;
  11924. }
  11925. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  11926. if (o == NULL)
  11927. {
  11928. return ERR_INVALID_PARAMETER;
  11929. }
  11930. Zero(&t, sizeof(t));
  11931. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  11932. UniStrCpy(t.AccountName, sizeof(t.AccountName), GetParamUniStr(o, "[name]"));
  11933. // RPC call
  11934. ret = ScSetLinkOffline(ps->Rpc, &t);
  11935. if (ret != ERR_NO_ERROR)
  11936. {
  11937. // An error has occured
  11938. CmdPrintError(c, ret);
  11939. FreeParamValueList(o);
  11940. return ret;
  11941. }
  11942. FreeParamValueList(o);
  11943. return 0;
  11944. }
  11945. // Convert the string to pass / discard flag
  11946. bool StrToPassOrDiscard(char *str)
  11947. {
  11948. // Validate arguments
  11949. if (str == NULL)
  11950. {
  11951. return false;
  11952. }
  11953. if (ToInt(str) != 0)
  11954. {
  11955. return true;
  11956. }
  11957. if (StartWith(str, "p") || StartWith(str, "y") || StartWith(str, "t"))
  11958. {
  11959. return true;
  11960. }
  11961. return false;
  11962. }
  11963. // Convert the string to the protocol
  11964. UINT StrToProtocol(char *str)
  11965. {
  11966. if (IsEmptyStr(str))
  11967. {
  11968. return 0;
  11969. }
  11970. if (StartWith("ip", str))
  11971. {
  11972. return 0;
  11973. }
  11974. else if (StartWith("tcp", str))
  11975. {
  11976. return IP_PROTO_TCP;
  11977. }
  11978. else if (StartWith("udp", str))
  11979. {
  11980. return IP_PROTO_UDP;
  11981. }
  11982. else if (StartWith("icmpv4", str))
  11983. {
  11984. return IP_PROTO_ICMPV4;
  11985. }
  11986. else if (StartWith("icmpv6", str))
  11987. {
  11988. return IP_PROTO_ICMPV6;
  11989. }
  11990. if (ToInt(str) == 0)
  11991. {
  11992. if (StrCmpi(str, "0") == 0)
  11993. {
  11994. return 0;
  11995. }
  11996. else
  11997. {
  11998. return INFINITE;
  11999. }
  12000. }
  12001. if (ToInt(str) >= 256)
  12002. {
  12003. return INFINITE;
  12004. }
  12005. return ToInt(str);
  12006. }
  12007. // Check the protocol name
  12008. bool CmdEvalProtocol(CONSOLE *c, wchar_t *str, void *param)
  12009. {
  12010. char tmp[64];
  12011. // Validate arguments
  12012. if (c == NULL || str == NULL)
  12013. {
  12014. return false;
  12015. }
  12016. UniToStr(tmp, sizeof(tmp), str);
  12017. if (StrToProtocol(tmp) == INFINITE)
  12018. {
  12019. c->Write(c, _UU("CMD_PROTOCOL_EVAL_FAILED"));
  12020. return false;
  12021. }
  12022. return true;
  12023. }
  12024. // Parse the port range
  12025. bool ParsePortRange(char *str, UINT *start, UINT *end)
  12026. {
  12027. UINT a = 0, b = 0;
  12028. TOKEN_LIST *t;
  12029. // Validate arguments
  12030. if (str == NULL)
  12031. {
  12032. return false;
  12033. }
  12034. if (IsEmptyStr(str) == false)
  12035. {
  12036. t = ParseToken(str, "\t -");
  12037. if (t->NumTokens == 1)
  12038. {
  12039. a = b = ToInt(t->Token[0]);
  12040. }
  12041. else if (t->NumTokens == 2)
  12042. {
  12043. a = ToInt(t->Token[0]);
  12044. b = ToInt(t->Token[1]);
  12045. }
  12046. FreeToken(t);
  12047. if (a > b)
  12048. {
  12049. return false;
  12050. }
  12051. if (a >= 65536 || b >= 65536)
  12052. {
  12053. return false;
  12054. }
  12055. if (a == 0 && b != 0)
  12056. {
  12057. return false;
  12058. }
  12059. }
  12060. if (start != NULL)
  12061. {
  12062. *start = a;
  12063. }
  12064. if (end != NULL)
  12065. {
  12066. *end = b;
  12067. }
  12068. return true;
  12069. }
  12070. // Check the port range
  12071. bool CmdEvalPortRange(CONSOLE *c, wchar_t *str, void *param)
  12072. {
  12073. char tmp[64];
  12074. // Validate arguments
  12075. if (c == NULL || str == NULL)
  12076. {
  12077. return false;
  12078. }
  12079. UniToStr(tmp, sizeof(tmp), str);
  12080. if (ParsePortRange(tmp, NULL, NULL) == false)
  12081. {
  12082. c->Write(c, _UU("CMD_PORT_RANGE_EVAL_FAILED"));
  12083. return false;
  12084. }
  12085. return true;
  12086. }
  12087. // Parse the MAC address and the mask
  12088. bool ParseMacAddressAndMask(char *src, bool *check_mac, UCHAR *mac_bin, UCHAR *mask_bin)
  12089. {
  12090. TOKEN_LIST *t;
  12091. char *macstr, *maskstr;
  12092. UCHAR mac[6], mask[6];
  12093. bool ok = false;
  12094. // Validate arguments
  12095. if (src == NULL)
  12096. {
  12097. return false;
  12098. }
  12099. //Zero(mac, sizeof(mac));
  12100. //Zero(mask, sizeof(mask));
  12101. if(check_mac != NULL && mac_bin != NULL && mask_bin != NULL)
  12102. {
  12103. ok = true;
  12104. }
  12105. if(IsEmptyStr(src) != false)
  12106. {
  12107. if(ok != false)
  12108. {
  12109. *check_mac = false;
  12110. Zero(mac_bin, 6);
  12111. Zero(mask_bin, 6);
  12112. }
  12113. return true;
  12114. }
  12115. t = ParseToken(src, "/");
  12116. if(t->NumTokens != 2)
  12117. {
  12118. FreeToken(t);
  12119. return false;
  12120. }
  12121. macstr = t->Token[0];
  12122. maskstr = t->Token[1];
  12123. Trim(macstr);
  12124. Trim(maskstr);
  12125. if(StrToMac(mac, macstr) == false || StrToMac(mask, maskstr) == false)
  12126. {
  12127. FreeToken(t);
  12128. return false;
  12129. }
  12130. else
  12131. {
  12132. if(ok != false)
  12133. {
  12134. Copy(mac_bin, mac, 6);
  12135. Copy(mask_bin, mask, 6);
  12136. *check_mac = true;
  12137. }
  12138. }
  12139. FreeToken(t);
  12140. return true;
  12141. }
  12142. // Check the MAC address and mask
  12143. bool CmdEvalMacAddressAndMask(CONSOLE *c, wchar_t *str, void *param)
  12144. {
  12145. char tmp[64];
  12146. // Validate arguments
  12147. if(c == NULL || str == NULL)
  12148. {
  12149. return false;
  12150. }
  12151. UniToStr(tmp, sizeof(tmp), str);
  12152. if(ParseMacAddressAndMask(tmp, NULL, NULL, NULL) == false)
  12153. {
  12154. c->Write(c, _UU("CMD_MAC_ADDRESS_AND_MASK_EVAL_FAILED"));
  12155. return false;
  12156. }
  12157. return true;
  12158. }
  12159. // Parse the status of TCP connection
  12160. bool ParseTcpState(char *src, bool *check_tcp_state, bool *established)
  12161. {
  12162. bool ok = false;
  12163. // Validate arguments
  12164. if(src == NULL)
  12165. {
  12166. return false;
  12167. }
  12168. if(check_tcp_state != NULL && established != NULL)
  12169. {
  12170. ok = true;
  12171. }
  12172. if (IsEmptyStr(src) == false)
  12173. {
  12174. if (StartWith("Established", src) == 0)
  12175. {
  12176. if(ok != false)
  12177. {
  12178. *check_tcp_state = true;
  12179. *established = true;
  12180. }
  12181. }
  12182. else if (StartWith("Unestablished", src) == 0)
  12183. {
  12184. if(ok != false)
  12185. {
  12186. *check_tcp_state = true;
  12187. *established = false;
  12188. }
  12189. }
  12190. else
  12191. {
  12192. // Illegal string
  12193. return false;
  12194. }
  12195. }
  12196. else
  12197. {
  12198. if(ok != false)
  12199. {
  12200. *check_tcp_state = false;
  12201. *established = false;
  12202. }
  12203. }
  12204. return true;
  12205. }
  12206. // Check the status of the TCP connection
  12207. bool CmdEvalTcpState(CONSOLE *c, wchar_t *str, void *param)
  12208. {
  12209. char tmp[64];
  12210. // Validate arguments
  12211. if(c == NULL || str == NULL)
  12212. {
  12213. return false;
  12214. }
  12215. UniToStr(tmp, sizeof(tmp), str);
  12216. if(ParseTcpState(tmp, NULL, NULL) == false)
  12217. {
  12218. c->Write(c, _UU("CMD_TCP_CONNECTION_STATE_EVAL_FAILED"));
  12219. return false;
  12220. }
  12221. return true;
  12222. }
  12223. // Adding a rule to the access list (Standard, IPv4)
  12224. UINT PsAccessAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  12225. {
  12226. LIST *o;
  12227. PS *ps = (PS *)param;
  12228. UINT ret = 0;
  12229. RPC_ADD_ACCESS t;
  12230. ACCESS *a;
  12231. // Parameter list that can be specified
  12232. CMD_EVAL_MIN_MAX minmax =
  12233. {
  12234. "CMD_AccessAdd_Eval_PRIORITY", 1, 4294967295UL,
  12235. };
  12236. PARAM args[] =
  12237. {
  12238. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  12239. {"[pass|discard]", CmdPrompt, _UU("CMD_AccessAdd_Prompt_TYPE"), CmdEvalNotEmpty, NULL},
  12240. {"MEMO", CmdPrompt, _UU("CMD_AccessAdd_Prompt_MEMO"), NULL, NULL},
  12241. {"PRIORITY", CmdPrompt, _UU("CMD_AccessAdd_Prompt_PRIORITY"), CmdEvalMinMax, &minmax},
  12242. {"SRCUSERNAME", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCUSERNAME"), NULL, NULL},
  12243. {"DESTUSERNAME", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTUSERNAME"), NULL, NULL},
  12244. {"SRCMAC", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCMAC"), CmdEvalMacAddressAndMask, NULL},
  12245. {"DESTMAC", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTMAC"), CmdEvalMacAddressAndMask, NULL},
  12246. {"SRCIP", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCIP"), CmdEvalIpAndMask4, NULL},
  12247. {"DESTIP", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTIP"), CmdEvalIpAndMask4, NULL},
  12248. {"PROTOCOL", CmdPrompt, _UU("CMD_AccessAdd_Prompt_PROTOCOL"), CmdEvalProtocol, NULL},
  12249. {"SRCPORT", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCPORT"), CmdEvalPortRange, NULL},
  12250. {"DESTPORT", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTPORT"), CmdEvalPortRange, NULL},
  12251. {"TCPSTATE", CmdPrompt, _UU("CMD_AccessAdd_Prompt_TCPSTATE"), CmdEvalTcpState, NULL},
  12252. };
  12253. // If virtual HUB is not selected, it's an error
  12254. if (ps->HubName == NULL)
  12255. {
  12256. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  12257. return ERR_INVALID_PARAMETER;
  12258. }
  12259. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  12260. if (o == NULL)
  12261. {
  12262. return ERR_INVALID_PARAMETER;
  12263. }
  12264. Zero(&t, sizeof(t));
  12265. a = &t.Access;
  12266. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  12267. UniStrCpy(a->Note, sizeof(a->Note), GetParamUniStr(o, "MEMO"));
  12268. a->Active = true;
  12269. a->Priority = GetParamInt(o, "PRIORITY");
  12270. a->Discard = StrToPassOrDiscard(GetParamStr(o, "[pass|discard]")) ? false : true;
  12271. StrCpy(a->SrcUsername, sizeof(a->SrcUsername), GetParamStr(o, "SRCUSERNAME"));
  12272. StrCpy(a->DestUsername, sizeof(a->DestUsername), GetParamStr(o, "DESTUSERNAME"));
  12273. ParseMacAddressAndMask(GetParamStr(o, "SRCMAC"), &a->CheckSrcMac, a->SrcMacAddress, a->SrcMacMask);
  12274. ParseMacAddressAndMask(GetParamStr(o, "DESTMAC"), &a->CheckDstMac, a->DstMacAddress, a->DstMacMask);
  12275. ParseIpAndMask4(GetParamStr(o, "SRCIP"), &a->SrcIpAddress, &a->SrcSubnetMask);
  12276. ParseIpAndMask4(GetParamStr(o, "DESTIP"), &a->DestIpAddress, &a->DestSubnetMask);
  12277. a->Protocol = StrToProtocol(GetParamStr(o, "PROTOCOL"));
  12278. ParsePortRange(GetParamStr(o, "SRCPORT"), &a->SrcPortStart, &a->SrcPortEnd);
  12279. ParsePortRange(GetParamStr(o, "DESTPORT"), &a->DestPortStart, &a->DestPortEnd);
  12280. ParseTcpState(GetParamStr(o, "TCPSTATE"), &a->CheckTcpState, &a->Established);
  12281. // RPC call
  12282. ret = ScAddAccess(ps->Rpc, &t);
  12283. if (ret != ERR_NO_ERROR)
  12284. {
  12285. // An error has occured
  12286. CmdPrintError(c, ret);
  12287. FreeParamValueList(o);
  12288. return ret;
  12289. }
  12290. FreeParamValueList(o);
  12291. return 0;
  12292. }
  12293. // Adding a rule to the access list (Extended, IPv4)
  12294. UINT PsAccessAddEx(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  12295. {
  12296. LIST *o;
  12297. PS *ps = (PS *)param;
  12298. UINT ret = 0;
  12299. RPC_ADD_ACCESS t;
  12300. ACCESS *a;
  12301. // Parameter list that can be specified
  12302. CMD_EVAL_MIN_MAX minmax =
  12303. {
  12304. "CMD_AccessAdd_Eval_PRIORITY", 1, 4294967295UL,
  12305. };
  12306. CMD_EVAL_MIN_MAX minmax_delay =
  12307. {
  12308. "CMD_AccessAddEx_Eval_DELAY", 0, HUB_ACCESSLIST_DELAY_MAX,
  12309. };
  12310. CMD_EVAL_MIN_MAX minmax_jitter =
  12311. {
  12312. "CMD_AccessAddEx_Eval_JITTER", 0, HUB_ACCESSLIST_JITTER_MAX,
  12313. };
  12314. CMD_EVAL_MIN_MAX minmax_loss =
  12315. {
  12316. "CMD_AccessAddEx_Eval_LOSS", 0, HUB_ACCESSLIST_LOSS_MAX,
  12317. };
  12318. PARAM args[] =
  12319. {
  12320. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  12321. {"[pass|discard]", CmdPrompt, _UU("CMD_AccessAdd_Prompt_TYPE"), CmdEvalNotEmpty, NULL},
  12322. {"MEMO", CmdPrompt, _UU("CMD_AccessAdd_Prompt_MEMO"), NULL, NULL},
  12323. {"PRIORITY", CmdPrompt, _UU("CMD_AccessAdd_Prompt_PRIORITY"), CmdEvalMinMax, &minmax},
  12324. {"SRCUSERNAME", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCUSERNAME"), NULL, NULL},
  12325. {"DESTUSERNAME", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTUSERNAME"), NULL, NULL},
  12326. {"SRCMAC", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCMAC"), CmdEvalMacAddressAndMask, NULL},
  12327. {"DESTMAC", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTMAC"), CmdEvalMacAddressAndMask, NULL},
  12328. {"SRCIP", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCIP"), CmdEvalIpAndMask4, NULL},
  12329. {"DESTIP", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTIP"), CmdEvalIpAndMask4, NULL},
  12330. {"PROTOCOL", CmdPrompt, _UU("CMD_AccessAdd_Prompt_PROTOCOL"), CmdEvalProtocol, NULL},
  12331. {"SRCPORT", CmdPrompt, _UU("CMD_AccessAdd_Prompt_SRCPORT"), CmdEvalPortRange, NULL},
  12332. {"DESTPORT", CmdPrompt, _UU("CMD_AccessAdd_Prompt_DESTPORT"), CmdEvalPortRange, NULL},
  12333. {"TCPSTATE", CmdPrompt, _UU("CMD_AccessAdd_Prompt_TCPSTATE"), CmdEvalTcpState, NULL},
  12334. {"DELAY", CmdPrompt, _UU("CMD_AccessAddEx_Prompt_DELAY"), CmdEvalMinMax, &minmax_delay},
  12335. {"JITTER", CmdPrompt, _UU("CMD_AccessAddEx_Prompt_JITTER"), CmdEvalMinMax, &minmax_jitter},
  12336. {"LOSS", CmdPrompt, _UU("CMD_AccessAddEx_Prompt_LOSS"), CmdEvalMinMax, &minmax_loss},
  12337. {"REDIRECTURL", NULL, NULL, NULL, NULL},
  12338. };
  12339. // If virtual HUB is not selected, it's an error
  12340. if (ps->HubName == NULL)
  12341. {
  12342. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  12343. return ERR_INVALID_PARAMETER;
  12344. }
  12345. // Check whether it is supported
  12346. if (GetCapsBool(ps->CapsList, "b_support_ex_acl") == false)
  12347. {
  12348. c->Write(c, _E(ERR_NOT_SUPPORTED));
  12349. return ERR_NOT_SUPPORTED;
  12350. }
  12351. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  12352. if (o == NULL)
  12353. {
  12354. return ERR_INVALID_PARAMETER;
  12355. }
  12356. Zero(&t, sizeof(t));
  12357. a = &t.Access;
  12358. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  12359. UniStrCpy(a->Note, sizeof(a->Note), GetParamUniStr(o, "MEMO"));
  12360. a->Active = true;
  12361. a->Priority = GetParamInt(o, "PRIORITY");
  12362. a->Discard = StrToPassOrDiscard(GetParamStr(o, "[pass|discard]")) ? false : true;
  12363. StrCpy(a->SrcUsername, sizeof(a->SrcUsername), GetParamStr(o, "SRCUSERNAME"));
  12364. StrCpy(a->DestUsername, sizeof(a->DestUsername), GetParamStr(o, "DESTUSERNAME"));
  12365. ParseMacAddressAndMask(GetParamStr(o, "SRCMAC"), &a->CheckSrcMac, a->SrcMacAddress, a->SrcMacMask);
  12366. ParseMacAddressAndMask(GetParamStr(o, "DESTMAC"), &a->CheckDstMac, a->DstMacAddress, a->DstMacMask);
  12367. ParseIpAndMask4(GetParamStr(o, "SRCIP"), &a->SrcIpAddress, &a->SrcSubnetMask);
  12368. ParseIpAndMask4(GetParamStr(o, "DESTIP"), &a->DestIpAddress, &a->DestSubnetMask);
  12369. a->Protocol = StrToProtocol(GetParamStr(o, "PROTOCOL"));
  12370. ParsePortRange(GetParamStr(o, "SRCPORT"), &a->SrcPortStart, &a->SrcPortEnd);
  12371. ParsePortRange(GetParamStr(o, "DESTPORT"), &a->DestPortStart, &a->DestPortEnd);
  12372. ParseTcpState(GetParamStr(o, "TCPSTATE"), &a->CheckTcpState, &a->Established);
  12373. a->Delay = GetParamInt(o, "DELAY");
  12374. a->Jitter = GetParamInt(o, "JITTER");
  12375. a->Loss = GetParamInt(o, "LOSS");
  12376. StrCpy(a->RedirectUrl, sizeof(a->RedirectUrl), GetParamStr(o, "REDIRECTURL"));
  12377. // RPC call
  12378. ret = ScAddAccess(ps->Rpc, &t);
  12379. if (ret != ERR_NO_ERROR)
  12380. {
  12381. // An error has occured
  12382. CmdPrintError(c, ret);
  12383. FreeParamValueList(o);
  12384. return ret;
  12385. }
  12386. FreeParamValueList(o);
  12387. return 0;
  12388. }
  12389. // Adding a rule to the access list (Standard, IPv6)
  12390. UINT PsAccessAdd6(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  12391. {
  12392. LIST *o;
  12393. PS *ps = (PS *)param;
  12394. UINT ret = 0;
  12395. RPC_ADD_ACCESS t;
  12396. ACCESS *a;
  12397. IP ip, mask;
  12398. // Parameter list that can be specified
  12399. CMD_EVAL_MIN_MAX minmax =
  12400. {
  12401. "CMD_AccessAdd6_Eval_PRIORITY", 1, 4294967295UL,
  12402. };
  12403. PARAM args[] =
  12404. {
  12405. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  12406. {"[pass|discard]", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_TYPE"), CmdEvalNotEmpty, NULL},
  12407. {"MEMO", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_MEMO"), NULL, NULL},
  12408. {"PRIORITY", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_PRIORITY"), CmdEvalMinMax, &minmax},
  12409. {"SRCUSERNAME", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCUSERNAME"), NULL, NULL},
  12410. {"DESTUSERNAME", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTUSERNAME"), NULL, NULL},
  12411. {"SRCMAC", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCMAC"), CmdEvalMacAddressAndMask, NULL},
  12412. {"DESTMAC", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTMAC"), CmdEvalMacAddressAndMask, NULL},
  12413. {"SRCIP", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCIP"), CmdEvalIpAndMask6, NULL},
  12414. {"DESTIP", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTIP"), CmdEvalIpAndMask6, NULL},
  12415. {"PROTOCOL", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_PROTOCOL"), CmdEvalProtocol, NULL},
  12416. {"SRCPORT", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCPORT"), CmdEvalPortRange, NULL},
  12417. {"DESTPORT", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTPORT"), CmdEvalPortRange, NULL},
  12418. {"TCPSTATE", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_TCPSTATE"), CmdEvalTcpState, NULL},
  12419. };
  12420. // If virtual HUB is not selected, it's an error
  12421. if (ps->HubName == NULL)
  12422. {
  12423. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  12424. return ERR_INVALID_PARAMETER;
  12425. }
  12426. // Check whether it is supported
  12427. if (GetCapsBool(ps->CapsList, "b_support_ex_acl") == false)
  12428. {
  12429. c->Write(c, _E(ERR_NOT_SUPPORTED));
  12430. return ERR_NOT_SUPPORTED;
  12431. }
  12432. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  12433. if (o == NULL)
  12434. {
  12435. return ERR_INVALID_PARAMETER;
  12436. }
  12437. Zero(&t, sizeof(t));
  12438. a = &t.Access;
  12439. a->IsIPv6 = true;
  12440. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  12441. UniStrCpy(a->Note, sizeof(a->Note), GetParamUniStr(o, "MEMO"));
  12442. a->Active = true;
  12443. a->Priority = GetParamInt(o, "PRIORITY");
  12444. a->Discard = StrToPassOrDiscard(GetParamStr(o, "[pass|discard]")) ? false : true;
  12445. StrCpy(a->SrcUsername, sizeof(a->SrcUsername), GetParamStr(o, "SRCUSERNAME"));
  12446. StrCpy(a->DestUsername, sizeof(a->DestUsername), GetParamStr(o, "DESTUSERNAME"));
  12447. ParseMacAddressAndMask(GetParamStr(o, "SRCMAC"), &a->CheckSrcMac, a->SrcMacAddress, a->SrcMacMask);
  12448. ParseMacAddressAndMask(GetParamStr(o, "DESTMAC"), &a->CheckDstMac, a->DstMacAddress, a->DstMacMask);
  12449. Zero(&ip, sizeof(ip));
  12450. Zero(&mask, sizeof(mask));
  12451. ParseIpAndMask6(GetParamStr(o, "SRCIP"), &ip, &mask);
  12452. IPToIPv6Addr(&a->SrcIpAddress6, &ip);
  12453. IPToIPv6Addr(&a->SrcSubnetMask6, &mask);
  12454. ParseIpAndMask6(GetParamStr(o, "DESTIP"), &ip, &mask);
  12455. IPToIPv6Addr(&a->DestIpAddress6, &ip);
  12456. IPToIPv6Addr(&a->DestSubnetMask6, &mask);
  12457. a->Protocol = StrToProtocol(GetParamStr(o, "PROTOCOL"));
  12458. ParsePortRange(GetParamStr(o, "SRCPORT"), &a->SrcPortStart, &a->SrcPortEnd);
  12459. ParsePortRange(GetParamStr(o, "DESTPORT"), &a->DestPortStart, &a->DestPortEnd);
  12460. ParseTcpState(GetParamStr(o, "TCPSTATE"), &a->CheckTcpState, &a->Established);
  12461. // RPC call
  12462. ret = ScAddAccess(ps->Rpc, &t);
  12463. if (ret != ERR_NO_ERROR)
  12464. {
  12465. // An error has occured
  12466. CmdPrintError(c, ret);
  12467. FreeParamValueList(o);
  12468. return ret;
  12469. }
  12470. FreeParamValueList(o);
  12471. return 0;
  12472. }
  12473. // Adding a rule to the access list (Extended, IPv6)
  12474. UINT PsAccessAddEx6(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  12475. {
  12476. LIST *o;
  12477. PS *ps = (PS *)param;
  12478. UINT ret = 0;
  12479. RPC_ADD_ACCESS t;
  12480. ACCESS *a;
  12481. IP ip, mask;
  12482. // Parameter list that can be specified
  12483. CMD_EVAL_MIN_MAX minmax =
  12484. {
  12485. "CMD_AccessAdd6_Eval_PRIORITY", 1, 4294967295UL,
  12486. };
  12487. CMD_EVAL_MIN_MAX minmax_delay =
  12488. {
  12489. "CMD_AccessAddEx6_Eval_DELAY", 0, HUB_ACCESSLIST_DELAY_MAX,
  12490. };
  12491. CMD_EVAL_MIN_MAX minmax_jitter =
  12492. {
  12493. "CMD_AccessAddEx6_Eval_JITTER", 0, HUB_ACCESSLIST_JITTER_MAX,
  12494. };
  12495. CMD_EVAL_MIN_MAX minmax_loss =
  12496. {
  12497. "CMD_AccessAddEx6_Eval_LOSS", 0, HUB_ACCESSLIST_LOSS_MAX,
  12498. };
  12499. PARAM args[] =
  12500. {
  12501. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  12502. {"[pass|discard]", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_TYPE"), CmdEvalNotEmpty, NULL},
  12503. {"MEMO", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_MEMO"), NULL, NULL},
  12504. {"PRIORITY", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_PRIORITY"), CmdEvalMinMax, &minmax},
  12505. {"SRCUSERNAME", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCUSERNAME"), NULL, NULL},
  12506. {"DESTUSERNAME", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTUSERNAME"), NULL, NULL},
  12507. {"SRCMAC", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCMAC"), CmdEvalMacAddressAndMask, NULL},
  12508. {"DESTMAC", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTMAC"), CmdEvalMacAddressAndMask, NULL},
  12509. {"SRCIP", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCIP"), CmdEvalIpAndMask6, NULL},
  12510. {"DESTIP", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTIP"), CmdEvalIpAndMask6, NULL},
  12511. {"PROTOCOL", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_PROTOCOL"), CmdEvalProtocol, NULL},
  12512. {"SRCPORT", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_SRCPORT"), CmdEvalPortRange, NULL},
  12513. {"DESTPORT", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_DESTPORT"), CmdEvalPortRange, NULL},
  12514. {"TCPSTATE", CmdPrompt, _UU("CMD_AccessAdd6_Prompt_TCPSTATE"), CmdEvalTcpState, NULL},
  12515. {"DELAY", CmdPrompt, _UU("CMD_AccessAddEx6_Prompt_DELAY"), CmdEvalMinMax, &minmax_delay},
  12516. {"JITTER", CmdPrompt, _UU("CMD_AccessAddEx6_Prompt_JITTER"), CmdEvalMinMax, &minmax_jitter},
  12517. {"LOSS", CmdPrompt, _UU("CMD_AccessAddEx6_Prompt_LOSS"), CmdEvalMinMax, &minmax_loss},
  12518. {"REDIRECTURL", NULL, NULL, NULL, NULL},
  12519. };
  12520. // If virtual HUB is not selected, it's an error
  12521. if (ps->HubName == NULL)
  12522. {
  12523. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  12524. return ERR_INVALID_PARAMETER;
  12525. }
  12526. // Check whether it is supported
  12527. if (GetCapsBool(ps->CapsList, "b_support_ex_acl") == false)
  12528. {
  12529. c->Write(c, _E(ERR_NOT_SUPPORTED));
  12530. return ERR_NOT_SUPPORTED;
  12531. }
  12532. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  12533. if (o == NULL)
  12534. {
  12535. return ERR_INVALID_PARAMETER;
  12536. }
  12537. Zero(&t, sizeof(t));
  12538. a = &t.Access;
  12539. a->IsIPv6 = true;
  12540. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  12541. UniStrCpy(a->Note, sizeof(a->Note), GetParamUniStr(o, "MEMO"));
  12542. a->Active = true;
  12543. a->Priority = GetParamInt(o, "PRIORITY");
  12544. a->Discard = StrToPassOrDiscard(GetParamStr(o, "[pass|discard]")) ? false : true;
  12545. StrCpy(a->SrcUsername, sizeof(a->SrcUsername), GetParamStr(o, "SRCUSERNAME"));
  12546. StrCpy(a->DestUsername, sizeof(a->DestUsername), GetParamStr(o, "DESTUSERNAME"));
  12547. ParseMacAddressAndMask(GetParamStr(o, "SRCMAC"), &a->CheckSrcMac, a->SrcMacAddress, a->SrcMacMask);
  12548. ParseMacAddressAndMask(GetParamStr(o, "DESTMAC"), &a->CheckDstMac, a->DstMacAddress, a->DstMacMask);
  12549. Zero(&ip, sizeof(ip));
  12550. Zero(&mask, sizeof(mask));
  12551. ParseIpAndMask6(GetParamStr(o, "SRCIP"), &ip, &mask);
  12552. IPToIPv6Addr(&a->SrcIpAddress6, &ip);
  12553. IPToIPv6Addr(&a->SrcSubnetMask6, &mask);
  12554. ParseIpAndMask6(GetParamStr(o, "DESTIP"), &ip, &mask);
  12555. IPToIPv6Addr(&a->DestIpAddress6, &ip);
  12556. IPToIPv6Addr(&a->DestSubnetMask6, &mask);
  12557. a->Protocol = StrToProtocol(GetParamStr(o, "PROTOCOL"));
  12558. ParsePortRange(GetParamStr(o, "SRCPORT"), &a->SrcPortStart, &a->SrcPortEnd);
  12559. ParsePortRange(GetParamStr(o, "DESTPORT"), &a->DestPortStart, &a->DestPortEnd);
  12560. ParseTcpState(GetParamStr(o, "TCPSTATE"), &a->CheckTcpState, &a->Established);
  12561. a->Delay = GetParamInt(o, "DELAY");
  12562. a->Jitter = GetParamInt(o, "JITTER");
  12563. a->Loss = GetParamInt(o, "LOSS");
  12564. StrCpy(a->RedirectUrl, sizeof(a->RedirectUrl), GetParamStr(o, "REDIRECTURL"));
  12565. // RPC call
  12566. ret = ScAddAccess(ps->Rpc, &t);
  12567. if (ret != ERR_NO_ERROR)
  12568. {
  12569. // An error has occured
  12570. CmdPrintError(c, ret);
  12571. FreeParamValueList(o);
  12572. return ret;
  12573. }
  12574. FreeParamValueList(o);
  12575. return 0;
  12576. }
  12577. // Get the list of rules in the access list
  12578. UINT PsAccessList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  12579. {
  12580. LIST *o;
  12581. PS *ps = (PS *)param;
  12582. UINT ret = 0;
  12583. RPC_ENUM_ACCESS_LIST t;
  12584. CT *ct;
  12585. UINT i;
  12586. // If virtual HUB is not selected, it's an error
  12587. if (ps->HubName == NULL)
  12588. {
  12589. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  12590. return ERR_INVALID_PARAMETER;
  12591. }
  12592. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  12593. if (o == NULL)
  12594. {
  12595. return ERR_INVALID_PARAMETER;
  12596. }
  12597. Zero(&t, sizeof(t));
  12598. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  12599. // RPC call
  12600. ret = ScEnumAccess(ps->Rpc, &t);
  12601. if (ret != ERR_NO_ERROR)
  12602. {
  12603. // An error has occured
  12604. CmdPrintError(c, ret);
  12605. FreeParamValueList(o);
  12606. return ret;
  12607. }
  12608. ct = CtNew();
  12609. CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_0"), true);
  12610. CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_1"), true);
  12611. CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_2"), true);
  12612. CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_3"), true);
  12613. CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_6"), true);
  12614. CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_5"), false);
  12615. CtInsertColumn(ct, _UU("SM_ACCESS_COLUMN_4"), false);
  12616. for (i = 0;i < t.NumAccess;i++)
  12617. {
  12618. ACCESS *a = &t.Accesses[i];
  12619. char tmp[MAX_SIZE];
  12620. wchar_t tmp3[MAX_SIZE];
  12621. wchar_t tmp1[MAX_SIZE];
  12622. wchar_t tmp2[MAX_SIZE];
  12623. wchar_t tmp4[MAX_SIZE];
  12624. GetAccessListStr(tmp, sizeof(tmp), a);
  12625. UniToStru(tmp1, a->Priority);
  12626. StrToUni(tmp2, sizeof(tmp2), tmp);
  12627. UniToStru(tmp4, a->UniqueId);
  12628. if (a->UniqueId == 0)
  12629. {
  12630. UniStrCpy(tmp4, sizeof(tmp4), _UU("SEC_NONE"));
  12631. }
  12632. UniToStru(tmp3, a->Id);
  12633. CtInsert(ct,
  12634. tmp3,
  12635. a->Discard ? _UU("SM_ACCESS_DISCARD") : _UU("SM_ACCESS_PASS"),
  12636. a->Active ? _UU("SM_ACCESS_ENABLE") : _UU("SM_ACCESS_DISABLE"),
  12637. tmp1,
  12638. tmp4,
  12639. tmp2,
  12640. a->Note);
  12641. }
  12642. CtFreeEx(ct, c, true);
  12643. FreeRpcEnumAccessList(&t);
  12644. FreeParamValueList(o);
  12645. return 0;
  12646. }
  12647. // Remove a rule from the access list
  12648. UINT PsAccessDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  12649. {
  12650. LIST *o;
  12651. PS *ps = (PS *)param;
  12652. UINT ret = 0;
  12653. RPC_DELETE_ACCESS t;
  12654. // Parameter list that can be specified
  12655. PARAM args[] =
  12656. {
  12657. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  12658. {"[id]", CmdPrompt, _UU("CMD_Access_Prompt_ID"), CmdEvalNotEmpty, NULL},
  12659. };
  12660. // If virtual HUB is not selected, it's an error
  12661. if (ps->HubName == NULL)
  12662. {
  12663. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  12664. return ERR_INVALID_PARAMETER;
  12665. }
  12666. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  12667. if (o == NULL)
  12668. {
  12669. return ERR_INVALID_PARAMETER;
  12670. }
  12671. Zero(&t, sizeof(t));
  12672. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  12673. t.Id = GetParamInt(o, "[id]");
  12674. // RPC call
  12675. ret = ScDeleteAccess(ps->Rpc, &t);
  12676. if (ret != ERR_NO_ERROR)
  12677. {
  12678. // An error has occured
  12679. CmdPrintError(c, ret);
  12680. FreeParamValueList(o);
  12681. return ret;
  12682. }
  12683. FreeParamValueList(o);
  12684. return 0;
  12685. }
  12686. // Enable the rule of access list
  12687. UINT PsAccessEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  12688. {
  12689. LIST *o;
  12690. PS *ps = (PS *)param;
  12691. UINT ret = 0;
  12692. RPC_ENUM_ACCESS_LIST t;
  12693. // Parameter list that can be specified
  12694. PARAM args[] =
  12695. {
  12696. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  12697. {"[id]", CmdPrompt, _UU("CMD_Access_Prompt_ID"), CmdEvalNotEmpty, NULL},
  12698. };
  12699. // If virtual HUB is not selected, it's an error
  12700. if (ps->HubName == NULL)
  12701. {
  12702. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  12703. return ERR_INVALID_PARAMETER;
  12704. }
  12705. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  12706. if (o == NULL)
  12707. {
  12708. return ERR_INVALID_PARAMETER;
  12709. }
  12710. Zero(&t, sizeof(t));
  12711. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  12712. // RPC call
  12713. ret = ScEnumAccess(ps->Rpc, &t);
  12714. if (ret != ERR_NO_ERROR)
  12715. {
  12716. // An error has occured
  12717. CmdPrintError(c, ret);
  12718. FreeParamValueList(o);
  12719. return ret;
  12720. }
  12721. else
  12722. {
  12723. UINT i;
  12724. bool b = false;
  12725. for (i = 0;i < t.NumAccess;i++)
  12726. {
  12727. ACCESS *a = &t.Accesses[i];
  12728. if (a->Id == GetParamInt(o, "[id]"))
  12729. {
  12730. b = true;
  12731. a->Active = true;
  12732. }
  12733. }
  12734. if (b == false)
  12735. {
  12736. // The specified ID is not found
  12737. ret = ERR_OBJECT_NOT_FOUND;
  12738. CmdPrintError(c, ret);
  12739. FreeParamValueList(o);
  12740. FreeRpcEnumAccessList(&t);
  12741. return ret;
  12742. }
  12743. ret = ScSetAccessList(ps->Rpc, &t);
  12744. if (ret != ERR_NO_ERROR)
  12745. {
  12746. // An error has occured
  12747. CmdPrintError(c, ret);
  12748. FreeParamValueList(o);
  12749. return ret;
  12750. }
  12751. FreeRpcEnumAccessList(&t);
  12752. }
  12753. FreeParamValueList(o);
  12754. return ret;
  12755. }
  12756. // Disable the rule of access list
  12757. UINT PsAccessDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  12758. {
  12759. LIST *o;
  12760. PS *ps = (PS *)param;
  12761. UINT ret = 0;
  12762. RPC_ENUM_ACCESS_LIST t;
  12763. // Parameter list that can be specified
  12764. PARAM args[] =
  12765. {
  12766. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  12767. {"[id]", CmdPrompt, _UU("CMD_Access_Prompt_ID"), CmdEvalNotEmpty, NULL},
  12768. };
  12769. // If virtual HUB is not selected, it's an error
  12770. if (ps->HubName == NULL)
  12771. {
  12772. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  12773. return ERR_INVALID_PARAMETER;
  12774. }
  12775. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  12776. if (o == NULL)
  12777. {
  12778. return ERR_INVALID_PARAMETER;
  12779. }
  12780. Zero(&t, sizeof(t));
  12781. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  12782. // RPC call
  12783. ret = ScEnumAccess(ps->Rpc, &t);
  12784. if (ret != ERR_NO_ERROR)
  12785. {
  12786. // An error has occured
  12787. CmdPrintError(c, ret);
  12788. FreeParamValueList(o);
  12789. return ret;
  12790. }
  12791. else
  12792. {
  12793. UINT i;
  12794. bool b = false;
  12795. for (i = 0;i < t.NumAccess;i++)
  12796. {
  12797. ACCESS *a = &t.Accesses[i];
  12798. if (a->Id == GetParamInt(o, "[id]"))
  12799. {
  12800. b = true;
  12801. a->Active = false;
  12802. }
  12803. }
  12804. if (b == false)
  12805. {
  12806. // The specified ID is not found
  12807. ret = ERR_OBJECT_NOT_FOUND;
  12808. CmdPrintError(c, ret);
  12809. FreeParamValueList(o);
  12810. FreeRpcEnumAccessList(&t);
  12811. return ret;
  12812. }
  12813. ret = ScSetAccessList(ps->Rpc, &t);
  12814. if (ret != ERR_NO_ERROR)
  12815. {
  12816. // An error has occured
  12817. CmdPrintError(c, ret);
  12818. FreeParamValueList(o);
  12819. return ret;
  12820. }
  12821. FreeRpcEnumAccessList(&t);
  12822. }
  12823. FreeParamValueList(o);
  12824. return ret;
  12825. }
  12826. // Get the user list
  12827. UINT PsUserList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  12828. {
  12829. LIST *o;
  12830. PS *ps = (PS *)param;
  12831. UINT ret = 0;
  12832. RPC_ENUM_USER t;
  12833. // If virtual HUB is not selected, it's an error
  12834. if (ps->HubName == NULL)
  12835. {
  12836. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  12837. return ERR_INVALID_PARAMETER;
  12838. }
  12839. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  12840. if (o == NULL)
  12841. {
  12842. return ERR_INVALID_PARAMETER;
  12843. }
  12844. Zero(&t, sizeof(t));
  12845. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  12846. // RPC call
  12847. ret = ScEnumUser(ps->Rpc, &t);
  12848. if (ret != ERR_NO_ERROR)
  12849. {
  12850. // An error has occured
  12851. CmdPrintError(c, ret);
  12852. FreeParamValueList(o);
  12853. return ret;
  12854. }
  12855. else
  12856. {
  12857. UINT i;
  12858. CT *ct = CtNew();
  12859. CtInsertColumn(ct, _UU("SM_USER_COLUMN_1"), false);
  12860. CtInsertColumn(ct, _UU("SM_USER_COLUMN_2"), false);
  12861. CtInsertColumn(ct, _UU("SM_USER_COLUMN_3"), false);
  12862. CtInsertColumn(ct, _UU("SM_USER_COLUMN_4"), false);
  12863. CtInsertColumn(ct, _UU("SM_USER_COLUMN_5"), false);
  12864. CtInsertColumn(ct, _UU("SM_USER_COLUMN_6"), false);
  12865. CtInsertColumn(ct, _UU("SM_USER_COLUMN_7"), false);
  12866. CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_5"), false);
  12867. CtInsertColumn(ct, _UU("SM_SESS_COLUMN_6"), false);
  12868. CtInsertColumn(ct, _UU("SM_SESS_COLUMN_7"), false);
  12869. for (i = 0;i < t.NumUser;i++)
  12870. {
  12871. RPC_ENUM_USER_ITEM *e = &t.Users[i];
  12872. wchar_t name[MAX_SIZE];
  12873. wchar_t group[MAX_SIZE];
  12874. wchar_t num[MAX_SIZE];
  12875. wchar_t time[MAX_SIZE];
  12876. wchar_t exp[MAX_SIZE];
  12877. wchar_t num1[64], num2[64];
  12878. StrToUni(name, sizeof(name), e->Name);
  12879. if (StrLen(e->GroupName) != 0)
  12880. {
  12881. StrToUni(group, sizeof(group), e->GroupName);
  12882. }
  12883. else
  12884. {
  12885. UniStrCpy(group, sizeof(group), _UU("SM_NO_GROUP"));
  12886. }
  12887. UniToStru(num, e->NumLogin);
  12888. GetDateTimeStrEx64(time, sizeof(time), SystemToLocal64(e->LastLoginTime), NULL);
  12889. if (e->IsExpiresFilled == false)
  12890. {
  12891. UniStrCpy(exp, sizeof(exp), _UU("CM_ST_NONE"));
  12892. }
  12893. else
  12894. {
  12895. if (e->Expires == 0)
  12896. {
  12897. UniStrCpy(exp, sizeof(exp), _UU("SM_LICENSE_NO_EXPIRES"));
  12898. }
  12899. else
  12900. {
  12901. GetDateTimeStrEx64(exp, sizeof(exp), SystemToLocal64(e->Expires), NULL);
  12902. }
  12903. }
  12904. if (e->IsTrafficFilled == false)
  12905. {
  12906. UniStrCpy(num1, sizeof(num1), _UU("CM_ST_NONE"));
  12907. UniStrCpy(num2, sizeof(num2), _UU("CM_ST_NONE"));
  12908. }
  12909. else
  12910. {
  12911. UniToStr3(num1, sizeof(num1),
  12912. e->Traffic.Recv.BroadcastBytes + e->Traffic.Recv.UnicastBytes +
  12913. e->Traffic.Send.BroadcastBytes + e->Traffic.Send.UnicastBytes);
  12914. UniToStr3(num2, sizeof(num2),
  12915. e->Traffic.Recv.BroadcastCount + e->Traffic.Recv.UnicastCount +
  12916. e->Traffic.Send.BroadcastBytes + e->Traffic.Send.UnicastCount);
  12917. }
  12918. CtInsert(ct,
  12919. name, e->Realname, group, e->Note, GetAuthTypeStr(e->AuthType),
  12920. num, time, exp, num1, num2);
  12921. }
  12922. CtFreeEx(ct, c, true);
  12923. }
  12924. FreeRpcEnumUser(&t);
  12925. FreeParamValueList(o);
  12926. return 0;
  12927. }
  12928. // Get a string of user authentication method
  12929. wchar_t *GetAuthTypeStr(UINT id)
  12930. {
  12931. char tmp[MAX_SIZE];
  12932. Format(tmp, sizeof(tmp), "SM_AUTHTYPE_%u", id);
  12933. return _UU(tmp);
  12934. }
  12935. // Creating a user
  12936. UINT PsUserCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  12937. {
  12938. LIST *o;
  12939. PS *ps = (PS *)param;
  12940. UINT ret = 0;
  12941. RPC_SET_USER t;
  12942. // Parameter list that can be specified
  12943. PARAM args[] =
  12944. {
  12945. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  12946. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  12947. {"GROUP", CmdPrompt, _UU("CMD_UserCreate_Prompt_GROUP"), NULL, NULL},
  12948. {"REALNAME", CmdPrompt, _UU("CMD_UserCreate_Prompt_REALNAME"), NULL, NULL},
  12949. {"NOTE", CmdPrompt, _UU("CMD_UserCreate_Prompt_NOTE"), NULL, NULL},
  12950. };
  12951. // If virtual HUB is not selected, it's an error
  12952. if (ps->HubName == NULL)
  12953. {
  12954. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  12955. return ERR_INVALID_PARAMETER;
  12956. }
  12957. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  12958. if (o == NULL)
  12959. {
  12960. return ERR_INVALID_PARAMETER;
  12961. }
  12962. Zero(&t, sizeof(t));
  12963. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  12964. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  12965. StrCpy(t.GroupName, sizeof(t.GroupName), GetParamStr(o, "GROUP"));
  12966. UniStrCpy(t.Realname, sizeof(t.Realname), GetParamUniStr(o, "REALNAME"));
  12967. UniStrCpy(t.Note, sizeof(t.Note), GetParamUniStr(o, "NOTE"));
  12968. Trim(t.Name);
  12969. if (StrCmpi(t.Name, "*") == 0)
  12970. {
  12971. t.AuthType = AUTHTYPE_RADIUS;
  12972. t.AuthData = NewRadiusAuthData(NULL);
  12973. }
  12974. else
  12975. {
  12976. UCHAR random_pass[SHA1_SIZE];
  12977. UCHAR random_pass2[MD5_SIZE];
  12978. Rand(random_pass, sizeof(random_pass));
  12979. Rand(random_pass2, sizeof(random_pass2));
  12980. t.AuthType = AUTHTYPE_PASSWORD;
  12981. t.AuthData = NewPasswordAuthDataRaw(random_pass, random_pass2);
  12982. }
  12983. // RPC call
  12984. ret = ScCreateUser(ps->Rpc, &t);
  12985. if (ret != ERR_NO_ERROR)
  12986. {
  12987. // An error has occured
  12988. CmdPrintError(c, ret);
  12989. FreeParamValueList(o);
  12990. return ret;
  12991. }
  12992. FreeRpcSetUser(&t);
  12993. FreeParamValueList(o);
  12994. return 0;
  12995. }
  12996. // Change the user information
  12997. UINT PsUserSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  12998. {
  12999. LIST *o;
  13000. PS *ps = (PS *)param;
  13001. UINT ret = 0;
  13002. RPC_SET_USER t;
  13003. // Parameter list that can be specified
  13004. PARAM args[] =
  13005. {
  13006. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13007. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13008. {"GROUP", CmdPrompt, _UU("CMD_UserCreate_Prompt_GROUP"), NULL, NULL},
  13009. {"REALNAME", CmdPrompt, _UU("CMD_UserCreate_Prompt_REALNAME"), NULL, NULL},
  13010. {"NOTE", CmdPrompt, _UU("CMD_UserCreate_Prompt_NOTE"), NULL, NULL},
  13011. };
  13012. // If virtual HUB is not selected, it's an error
  13013. if (ps->HubName == NULL)
  13014. {
  13015. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13016. return ERR_INVALID_PARAMETER;
  13017. }
  13018. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13019. if (o == NULL)
  13020. {
  13021. return ERR_INVALID_PARAMETER;
  13022. }
  13023. Zero(&t, sizeof(t));
  13024. // Get the user object
  13025. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13026. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13027. ret = ScGetUser(ps->Rpc, &t);
  13028. if (ret != ERR_NO_ERROR)
  13029. {
  13030. // An error has occured
  13031. CmdPrintError(c, ret);
  13032. FreeParamValueList(o);
  13033. return ret;
  13034. }
  13035. // Update the information
  13036. StrCpy(t.GroupName, sizeof(t.GroupName), GetParamStr(o, "GROUP"));
  13037. UniStrCpy(t.Realname, sizeof(t.Realname), GetParamUniStr(o, "REALNAME"));
  13038. UniStrCpy(t.Note, sizeof(t.Note), GetParamUniStr(o, "NOTE"));
  13039. // Write the user object
  13040. ret = ScSetUser(ps->Rpc, &t);
  13041. if (ret != ERR_NO_ERROR)
  13042. {
  13043. // An error has occured
  13044. CmdPrintError(c, ret);
  13045. FreeParamValueList(o);
  13046. return ret;
  13047. }
  13048. FreeRpcSetUser(&t);
  13049. FreeParamValueList(o);
  13050. return 0;
  13051. }
  13052. // Delete the user
  13053. UINT PsUserDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13054. {
  13055. LIST *o;
  13056. PS *ps = (PS *)param;
  13057. UINT ret = 0;
  13058. RPC_DELETE_USER t;
  13059. // Parameter list that can be specified
  13060. PARAM args[] =
  13061. {
  13062. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13063. };
  13064. // If virtual HUB is not selected, it's an error
  13065. if (ps->HubName == NULL)
  13066. {
  13067. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13068. return ERR_INVALID_PARAMETER;
  13069. }
  13070. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13071. if (o == NULL)
  13072. {
  13073. return ERR_INVALID_PARAMETER;
  13074. }
  13075. Zero(&t, sizeof(t));
  13076. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13077. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13078. // RPC call
  13079. ret = ScDeleteUser(ps->Rpc, &t);
  13080. if (ret != ERR_NO_ERROR)
  13081. {
  13082. // An error has occured
  13083. CmdPrintError(c, ret);
  13084. FreeParamValueList(o);
  13085. return ret;
  13086. }
  13087. FreeParamValueList(o);
  13088. return 0;
  13089. }
  13090. // Get the user information
  13091. UINT PsUserGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13092. {
  13093. LIST *o;
  13094. PS *ps = (PS *)param;
  13095. UINT ret = 0;
  13096. RPC_SET_USER t;
  13097. // Parameter list that can be specified
  13098. PARAM args[] =
  13099. {
  13100. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13101. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13102. };
  13103. // If virtual HUB is not selected, it's an error
  13104. if (ps->HubName == NULL)
  13105. {
  13106. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13107. return ERR_INVALID_PARAMETER;
  13108. }
  13109. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13110. if (o == NULL)
  13111. {
  13112. return ERR_INVALID_PARAMETER;
  13113. }
  13114. Zero(&t, sizeof(t));
  13115. // Get the user object
  13116. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13117. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13118. ret = ScGetUser(ps->Rpc, &t);
  13119. if (ret != ERR_NO_ERROR)
  13120. {
  13121. // An error has occured
  13122. CmdPrintError(c, ret);
  13123. FreeParamValueList(o);
  13124. return ret;
  13125. }
  13126. else
  13127. {
  13128. wchar_t tmp[MAX_SIZE];
  13129. CT *ct;
  13130. // Display the user's data
  13131. ct = CtNewStandard();
  13132. // User name
  13133. StrToUni(tmp, sizeof(tmp), t.Name);
  13134. CtInsert(ct, _UU("CMD_UserGet_Column_Name"), tmp);
  13135. // Real name
  13136. CtInsert(ct, _UU("CMD_UserGet_Column_RealName"), t.Realname);
  13137. // Description
  13138. CtInsert(ct, _UU("CMD_UserGet_Column_Note"), t.Note);
  13139. // Group name
  13140. if (IsEmptyStr(t.GroupName) == false)
  13141. {
  13142. StrToUni(tmp, sizeof(tmp), t.GroupName);
  13143. CtInsert(ct, _UU("CMD_UserGet_Column_Group"), tmp);
  13144. }
  13145. // Expiration date
  13146. GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.ExpireTime), NULL);
  13147. CtInsert(ct, _UU("CMD_UserGet_Column_Expires"), tmp);
  13148. // Authentication method
  13149. CtInsert(ct, _UU("CMD_UserGet_Column_AuthType"), GetAuthTypeStr(t.AuthType));
  13150. switch (t.AuthType)
  13151. {
  13152. case AUTHTYPE_USERCERT:
  13153. if (t.AuthData != NULL)
  13154. {
  13155. AUTHUSERCERT *auc = (AUTHUSERCERT *)t.AuthData;
  13156. if (auc != NULL && auc->UserX != NULL)
  13157. {
  13158. // Registered user-specific certificate
  13159. GetAllNameFromX(tmp, sizeof(tmp), auc->UserX);
  13160. CtInsert(ct, _UU("CMD_UserGet_Column_UserCert"), tmp);
  13161. }
  13162. }
  13163. break;
  13164. case AUTHTYPE_ROOTCERT:
  13165. if (t.AuthData != NULL)
  13166. {
  13167. AUTHROOTCERT *arc = (AUTHROOTCERT *)t.AuthData;
  13168. if (IsEmptyUniStr(arc->CommonName) == false)
  13169. {
  13170. // Limitation the value of the certificate's CN
  13171. CtInsert(ct, _UU("CMD_UserGet_Column_RootCert_CN"), arc->CommonName);
  13172. }
  13173. if (arc->Serial != NULL && arc->Serial->size >= 1)
  13174. {
  13175. char tmp2[MAX_SIZE];
  13176. // Limitation the serial number of the certificate
  13177. BinToStrEx(tmp2, sizeof(tmp2), arc->Serial->data, arc->Serial->size);
  13178. StrToUni(tmp, sizeof(tmp), tmp2);
  13179. CtInsert(ct, _UU("CMD_UserGet_Column_RootCert_SERIAL"), tmp);
  13180. }
  13181. }
  13182. break;
  13183. case AUTHTYPE_RADIUS:
  13184. case AUTHTYPE_NT:
  13185. if (t.AuthData != NULL)
  13186. {
  13187. AUTHRADIUS *ar = (AUTHRADIUS *)t.AuthData;
  13188. // Authentication user name of the external authentication server
  13189. if (IsEmptyUniStr(ar->RadiusUsername) == false)
  13190. {
  13191. CtInsert(ct, _UU("CMD_UserGet_Column_RadiusAlias"), ar->RadiusUsername);
  13192. }
  13193. }
  13194. break;
  13195. }
  13196. CtInsert(ct, L"---", L"---");
  13197. GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.CreatedTime), NULL);
  13198. CtInsert(ct, _UU("SM_USERINFO_CREATE"), tmp);
  13199. GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.UpdatedTime), NULL);
  13200. CtInsert(ct, _UU("SM_USERINFO_UPDATE"), tmp);
  13201. CmdInsertTrafficInfo(ct, &t.Traffic);
  13202. UniToStru(tmp, t.NumLogin);
  13203. CtInsert(ct, _UU("SM_USERINFO_NUMLOGIN"), tmp);
  13204. CtFree(ct, c);
  13205. if (t.Policy != NULL)
  13206. {
  13207. c->Write(c, L"");
  13208. c->Write(c, _UU("CMD_UserGet_Policy"));
  13209. PrintPolicy(c, t.Policy, false);
  13210. }
  13211. }
  13212. FreeRpcSetUser(&t);
  13213. FreeParamValueList(o);
  13214. return 0;
  13215. }
  13216. // Set the authentication method for the user to the anonymous authentication
  13217. UINT PsUserAnonymousSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13218. {
  13219. LIST *o;
  13220. PS *ps = (PS *)param;
  13221. UINT ret = 0;
  13222. RPC_SET_USER t;
  13223. // Parameter list that can be specified
  13224. PARAM args[] =
  13225. {
  13226. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13227. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13228. };
  13229. // If virtual HUB is not selected, it's an error
  13230. if (ps->HubName == NULL)
  13231. {
  13232. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13233. return ERR_INVALID_PARAMETER;
  13234. }
  13235. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13236. if (o == NULL)
  13237. {
  13238. return ERR_INVALID_PARAMETER;
  13239. }
  13240. Zero(&t, sizeof(t));
  13241. // Get the user object
  13242. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13243. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13244. ret = ScGetUser(ps->Rpc, &t);
  13245. if (ret != ERR_NO_ERROR)
  13246. {
  13247. // An error has occured
  13248. CmdPrintError(c, ret);
  13249. FreeParamValueList(o);
  13250. return ret;
  13251. }
  13252. // Update the information
  13253. FreeAuthData(t.AuthType, t.AuthData);
  13254. // Set to anonymous authentication
  13255. t.AuthType = AUTHTYPE_ANONYMOUS;
  13256. t.AuthData = NULL;
  13257. // Write the user object
  13258. ret = ScSetUser(ps->Rpc, &t);
  13259. if (ret != ERR_NO_ERROR)
  13260. {
  13261. // An error has occured
  13262. CmdPrintError(c, ret);
  13263. FreeParamValueList(o);
  13264. return ret;
  13265. }
  13266. FreeRpcSetUser(&t);
  13267. FreeParamValueList(o);
  13268. return 0;
  13269. }
  13270. // Set the authentication method for the user to the password authentication and set a password
  13271. UINT PsUserPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13272. {
  13273. LIST *o;
  13274. PS *ps = (PS *)param;
  13275. UINT ret = 0;
  13276. RPC_SET_USER t;
  13277. // Parameter list that can be specified
  13278. PARAM args[] =
  13279. {
  13280. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13281. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13282. {"PASSWORD", CmdPromptChoosePassword, NULL, NULL, NULL},
  13283. };
  13284. // If virtual HUB is not selected, it's an error
  13285. if (ps->HubName == NULL)
  13286. {
  13287. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13288. return ERR_INVALID_PARAMETER;
  13289. }
  13290. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13291. if (o == NULL)
  13292. {
  13293. return ERR_INVALID_PARAMETER;
  13294. }
  13295. Zero(&t, sizeof(t));
  13296. // Get the user object
  13297. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13298. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13299. ret = ScGetUser(ps->Rpc, &t);
  13300. if (ret != ERR_NO_ERROR)
  13301. {
  13302. // An error has occured
  13303. CmdPrintError(c, ret);
  13304. FreeParamValueList(o);
  13305. return ret;
  13306. }
  13307. // Update the information
  13308. FreeAuthData(t.AuthType, t.AuthData);
  13309. {
  13310. AUTHPASSWORD *pw;
  13311. pw = NewPasswordAuthData(t.Name, GetParamStr(o, "PASSWORD"));
  13312. // Set to the password authentication
  13313. t.AuthType = AUTHTYPE_PASSWORD;
  13314. t.AuthData = pw;
  13315. }
  13316. // Write the user object
  13317. ret = ScSetUser(ps->Rpc, &t);
  13318. if (ret != ERR_NO_ERROR)
  13319. {
  13320. // An error has occured
  13321. CmdPrintError(c, ret);
  13322. FreeParamValueList(o);
  13323. return ret;
  13324. }
  13325. FreeRpcSetUser(&t);
  13326. FreeParamValueList(o);
  13327. return 0;
  13328. }
  13329. // Set the authentication method for the user to the specific certificate authentication and set a certificate
  13330. UINT PsUserCertSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13331. {
  13332. LIST *o;
  13333. PS *ps = (PS *)param;
  13334. UINT ret = 0;
  13335. RPC_SET_USER t;
  13336. X *x;
  13337. // Parameter list that can be specified
  13338. PARAM args[] =
  13339. {
  13340. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13341. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13342. {"LOADCERT", CmdPrompt, _UU("CMD_LOADCERTPATH"), CmdEvalIsFile, NULL},
  13343. };
  13344. // If virtual HUB is not selected, it's an error
  13345. if (ps->HubName == NULL)
  13346. {
  13347. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13348. return ERR_INVALID_PARAMETER;
  13349. }
  13350. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13351. if (o == NULL)
  13352. {
  13353. return ERR_INVALID_PARAMETER;
  13354. }
  13355. // Read the certificate
  13356. x = FileToXW(GetParamUniStr(o, "LOADCERT"));
  13357. if (x == NULL)
  13358. {
  13359. c->Write(c, _UU("CMD_LOADCERT_FAILED"));
  13360. FreeParamValueList(o);
  13361. return ERR_INTERNAL_ERROR;
  13362. }
  13363. Zero(&t, sizeof(t));
  13364. // Get the user object
  13365. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13366. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13367. ret = ScGetUser(ps->Rpc, &t);
  13368. if (ret != ERR_NO_ERROR)
  13369. {
  13370. // An error has occured
  13371. CmdPrintError(c, ret);
  13372. FreeParamValueList(o);
  13373. FreeX(x);
  13374. return ret;
  13375. }
  13376. // Update the information
  13377. FreeAuthData(t.AuthType, t.AuthData);
  13378. {
  13379. AUTHUSERCERT *c;
  13380. c = NewUserCertAuthData(x);
  13381. FreeX(x);
  13382. // Set to the password authentication
  13383. t.AuthType = AUTHTYPE_USERCERT;
  13384. t.AuthData = c;
  13385. }
  13386. // Write the user object
  13387. ret = ScSetUser(ps->Rpc, &t);
  13388. if (ret != ERR_NO_ERROR)
  13389. {
  13390. // An error has occured
  13391. CmdPrintError(c, ret);
  13392. FreeParamValueList(o);
  13393. return ret;
  13394. }
  13395. FreeRpcSetUser(&t);
  13396. FreeParamValueList(o);
  13397. return 0;
  13398. }
  13399. // Get certificates that are registered in the user which uses certificate authentication
  13400. UINT PsUserCertGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13401. {
  13402. LIST *o;
  13403. PS *ps = (PS *)param;
  13404. UINT ret = 0;
  13405. RPC_SET_USER t;
  13406. AUTHUSERCERT *a;
  13407. // Parameter list that can be specified
  13408. PARAM args[] =
  13409. {
  13410. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13411. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13412. {"SAVECERT", CmdPrompt, _UU("CMD_SAVECERTPATH"), NULL, NULL},
  13413. };
  13414. // If virtual HUB is not selected, it's an error
  13415. if (ps->HubName == NULL)
  13416. {
  13417. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13418. return ERR_INVALID_PARAMETER;
  13419. }
  13420. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13421. if (o == NULL)
  13422. {
  13423. return ERR_INVALID_PARAMETER;
  13424. }
  13425. Zero(&t, sizeof(t));
  13426. // Get the user object
  13427. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13428. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13429. ret = ScGetUser(ps->Rpc, &t);
  13430. if (ret != ERR_NO_ERROR)
  13431. {
  13432. // An error has occured
  13433. CmdPrintError(c, ret);
  13434. FreeParamValueList(o);
  13435. return ret;
  13436. }
  13437. a = (AUTHUSERCERT *)t.AuthData;
  13438. if (t.AuthType != AUTHTYPE_USERCERT || a == NULL || a->UserX == NULL)
  13439. {
  13440. // The user is not using specific certificate authentication
  13441. ret = ERR_INVALID_PARAMETER;
  13442. c->Write(c, _UU("CMD_UserCertGet_Not_Cert"));
  13443. }
  13444. else
  13445. {
  13446. if (XToFileW(a->UserX, GetParamUniStr(o, "SAVECERT"), true) == false)
  13447. {
  13448. c->Write(c, _UU("CMD_SAVECERT_FAILED"));
  13449. }
  13450. }
  13451. FreeRpcSetUser(&t);
  13452. FreeParamValueList(o);
  13453. return ret;
  13454. }
  13455. // Set the authentication method for the user to the signed certificate authentication
  13456. UINT PsUserSignedSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13457. {
  13458. LIST *o;
  13459. PS *ps = (PS *)param;
  13460. UINT ret = 0;
  13461. RPC_SET_USER t;
  13462. // Parameter list that can be specified
  13463. PARAM args[] =
  13464. {
  13465. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13466. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13467. {"CN", CmdPrompt, _UU("CMD_UserSignedSet_Prompt_CN"), NULL, NULL},
  13468. {"SERIAL", CmdPrompt, _UU("CMD_UserSignedSet_Prompt_SERIAL"), NULL, NULL},
  13469. };
  13470. // If virtual HUB is not selected, it's an error
  13471. if (ps->HubName == NULL)
  13472. {
  13473. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13474. return ERR_INVALID_PARAMETER;
  13475. }
  13476. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13477. if (o == NULL)
  13478. {
  13479. return ERR_INVALID_PARAMETER;
  13480. }
  13481. Zero(&t, sizeof(t));
  13482. // Get the user object
  13483. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13484. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13485. ret = ScGetUser(ps->Rpc, &t);
  13486. if (ret != ERR_NO_ERROR)
  13487. {
  13488. // An error has occured
  13489. CmdPrintError(c, ret);
  13490. FreeParamValueList(o);
  13491. return ret;
  13492. }
  13493. // Update the information
  13494. FreeAuthData(t.AuthType, t.AuthData);
  13495. {
  13496. AUTHROOTCERT *c;
  13497. BUF *b;
  13498. X_SERIAL *serial = NULL;
  13499. b = StrToBin(GetParamStr(o, "SERIAL"));
  13500. if (b != NULL && b->Size >= 1)
  13501. {
  13502. serial = NewXSerial(b->Buf, b->Size);
  13503. }
  13504. FreeBuf(b);
  13505. c = NewRootCertAuthData(serial, GetParamUniStr(o, "CN"));
  13506. FreeXSerial(serial);
  13507. // Set to the signed certificate authentication
  13508. t.AuthType = AUTHTYPE_ROOTCERT;
  13509. t.AuthData = c;
  13510. }
  13511. // Write the user object
  13512. ret = ScSetUser(ps->Rpc, &t);
  13513. if (ret != ERR_NO_ERROR)
  13514. {
  13515. // An error has occured
  13516. CmdPrintError(c, ret);
  13517. FreeParamValueList(o);
  13518. return ret;
  13519. }
  13520. FreeRpcSetUser(&t);
  13521. FreeParamValueList(o);
  13522. return 0;
  13523. }
  13524. // Set the authentication method for the user to the Radius authentication
  13525. UINT PsUserRadiusSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13526. {
  13527. LIST *o;
  13528. PS *ps = (PS *)param;
  13529. UINT ret = 0;
  13530. RPC_SET_USER t;
  13531. // Parameter list that can be specified
  13532. PARAM args[] =
  13533. {
  13534. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13535. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13536. {"ALIAS", CmdPrompt, _UU("CMD_UserRadiusSet_Prompt_ALIAS"), NULL, NULL},
  13537. };
  13538. // If virtual HUB is not selected, it's an error
  13539. if (ps->HubName == NULL)
  13540. {
  13541. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13542. return ERR_INVALID_PARAMETER;
  13543. }
  13544. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13545. if (o == NULL)
  13546. {
  13547. return ERR_INVALID_PARAMETER;
  13548. }
  13549. Zero(&t, sizeof(t));
  13550. // Get the user object
  13551. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13552. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13553. ret = ScGetUser(ps->Rpc, &t);
  13554. if (ret != ERR_NO_ERROR)
  13555. {
  13556. // An error has occured
  13557. CmdPrintError(c, ret);
  13558. FreeParamValueList(o);
  13559. return ret;
  13560. }
  13561. // Update the information
  13562. FreeAuthData(t.AuthType, t.AuthData);
  13563. {
  13564. AUTHRADIUS *a;
  13565. a = NewRadiusAuthData(GetParamUniStr(o, "ALIAS"));
  13566. // Set to Radius authentication
  13567. t.AuthType = AUTHTYPE_RADIUS;
  13568. t.AuthData = a;
  13569. }
  13570. // Write the user object
  13571. ret = ScSetUser(ps->Rpc, &t);
  13572. if (ret != ERR_NO_ERROR)
  13573. {
  13574. // An error has occured
  13575. CmdPrintError(c, ret);
  13576. FreeParamValueList(o);
  13577. return ret;
  13578. }
  13579. FreeRpcSetUser(&t);
  13580. FreeParamValueList(o);
  13581. return 0;
  13582. }
  13583. // Set the authentication method for the user to the NT domain authentication
  13584. UINT PsUserNTLMSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13585. {
  13586. LIST *o;
  13587. PS *ps = (PS *)param;
  13588. UINT ret = 0;
  13589. RPC_SET_USER t;
  13590. // Parameter list that can be specified
  13591. PARAM args[] =
  13592. {
  13593. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13594. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13595. {"ALIAS", CmdPrompt, _UU("CMD_UserRadiusSet_Prompt_ALIAS"), NULL, NULL},
  13596. };
  13597. // If virtual HUB is not selected, it's an error
  13598. if (ps->HubName == NULL)
  13599. {
  13600. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13601. return ERR_INVALID_PARAMETER;
  13602. }
  13603. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13604. if (o == NULL)
  13605. {
  13606. return ERR_INVALID_PARAMETER;
  13607. }
  13608. Zero(&t, sizeof(t));
  13609. // Get the user object
  13610. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13611. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13612. ret = ScGetUser(ps->Rpc, &t);
  13613. if (ret != ERR_NO_ERROR)
  13614. {
  13615. // An error has occured
  13616. CmdPrintError(c, ret);
  13617. FreeParamValueList(o);
  13618. return ret;
  13619. }
  13620. // Update the information
  13621. FreeAuthData(t.AuthType, t.AuthData);
  13622. {
  13623. AUTHRADIUS *a;
  13624. a = NewRadiusAuthData(GetParamUniStr(o, "ALIAS"));
  13625. // Set to the NT domain authentication
  13626. t.AuthType = AUTHTYPE_NT;
  13627. t.AuthData = a;
  13628. }
  13629. // Write the user object
  13630. ret = ScSetUser(ps->Rpc, &t);
  13631. if (ret != ERR_NO_ERROR)
  13632. {
  13633. // An error has occured
  13634. CmdPrintError(c, ret);
  13635. FreeParamValueList(o);
  13636. return ret;
  13637. }
  13638. FreeRpcSetUser(&t);
  13639. FreeParamValueList(o);
  13640. return 0;
  13641. }
  13642. // Delete the security policy of the user
  13643. UINT PsUserPolicyRemove(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13644. {
  13645. LIST *o;
  13646. PS *ps = (PS *)param;
  13647. UINT ret = 0;
  13648. RPC_SET_USER t;
  13649. // Parameter list that can be specified
  13650. PARAM args[] =
  13651. {
  13652. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13653. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13654. };
  13655. // If virtual HUB is not selected, it's an error
  13656. if (ps->HubName == NULL)
  13657. {
  13658. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13659. return ERR_INVALID_PARAMETER;
  13660. }
  13661. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13662. if (o == NULL)
  13663. {
  13664. return ERR_INVALID_PARAMETER;
  13665. }
  13666. Zero(&t, sizeof(t));
  13667. // Get the user object
  13668. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13669. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13670. ret = ScGetUser(ps->Rpc, &t);
  13671. if (ret != ERR_NO_ERROR)
  13672. {
  13673. // An error has occured
  13674. CmdPrintError(c, ret);
  13675. FreeParamValueList(o);
  13676. return ret;
  13677. }
  13678. // Update
  13679. if (t.Policy != NULL)
  13680. {
  13681. Free(t.Policy);
  13682. t.Policy = NULL;
  13683. }
  13684. // Write the user object
  13685. ret = ScSetUser(ps->Rpc, &t);
  13686. if (ret != ERR_NO_ERROR)
  13687. {
  13688. // An error has occured
  13689. CmdPrintError(c, ret);
  13690. FreeParamValueList(o);
  13691. return ret;
  13692. }
  13693. FreeRpcSetUser(&t);
  13694. FreeParamValueList(o);
  13695. return 0;
  13696. }
  13697. // Set a security policy of the user
  13698. UINT PsUserPolicySet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13699. {
  13700. LIST *o;
  13701. PS *ps = (PS *)param;
  13702. UINT ret = 0;
  13703. RPC_SET_USER t;
  13704. // Parameter list that can be specified
  13705. PARAM args[] =
  13706. {
  13707. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13708. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13709. {"NAME", CmdPrompt, _UU("CMD_CascadePolicySet_PROMPT_POLNAME"), CmdEvalNotEmpty, NULL},
  13710. {"VALUE", CmdPrompt, _UU("CMD_CascadePolicySet_PROMPT_POLVALUE"), CmdEvalNotEmpty, NULL},
  13711. };
  13712. // If virtual HUB is not selected, it's an error
  13713. if (ps->HubName == NULL)
  13714. {
  13715. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13716. return ERR_INVALID_PARAMETER;
  13717. }
  13718. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13719. if (o == NULL)
  13720. {
  13721. return ERR_INVALID_PARAMETER;
  13722. }
  13723. Zero(&t, sizeof(t));
  13724. // Get the user object
  13725. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13726. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13727. ret = ScGetUser(ps->Rpc, &t);
  13728. if (ret != ERR_NO_ERROR)
  13729. {
  13730. // An error has occured
  13731. CmdPrintError(c, ret);
  13732. FreeParamValueList(o);
  13733. return ret;
  13734. }
  13735. // Update
  13736. if (t.Policy == NULL)
  13737. {
  13738. t.Policy = ClonePolicy(GetDefaultPolicy());
  13739. }
  13740. // Edit
  13741. if (EditPolicy(c, t.Policy, GetParamStr(o, "NAME"), GetParamStr(o, "VALUE"), false) == false)
  13742. {
  13743. ret = ERR_INVALID_PARAMETER;
  13744. }
  13745. else
  13746. {
  13747. // Write the user object
  13748. ret = ScSetUser(ps->Rpc, &t);
  13749. if (ret != ERR_NO_ERROR)
  13750. {
  13751. // An error has occured
  13752. CmdPrintError(c, ret);
  13753. FreeParamValueList(o);
  13754. return ret;
  13755. }
  13756. }
  13757. FreeRpcSetUser(&t);
  13758. FreeParamValueList(o);
  13759. return ret;
  13760. }
  13761. // Convert the string to a date and time
  13762. UINT64 StrToDateTime64(char *str)
  13763. {
  13764. UINT64 ret = 0;
  13765. TOKEN_LIST *t;
  13766. UINT a, b, c, d, e, f;
  13767. // Validate arguments
  13768. if (str == NULL)
  13769. {
  13770. return INFINITE;
  13771. }
  13772. if (IsEmptyStr(str) || StrCmpi(str, "none") == 0)
  13773. {
  13774. return 0;
  13775. }
  13776. t = ParseToken(str, ":/,. \"");
  13777. if (t->NumTokens != 6)
  13778. {
  13779. FreeToken(t);
  13780. return INFINITE;
  13781. }
  13782. a = ToInt(t->Token[0]);
  13783. b = ToInt(t->Token[1]);
  13784. c = ToInt(t->Token[2]);
  13785. d = ToInt(t->Token[3]);
  13786. e = ToInt(t->Token[4]);
  13787. f = ToInt(t->Token[5]);
  13788. ret = INFINITE;
  13789. if (a >= 1000 && a <= 9999 && b >= 1 && b <= 12 && c >= 1 && c <= 31 &&
  13790. d >= 0 && d <= 23 && e >= 0 && e <= 59 && f >= 0 && f <= 59)
  13791. {
  13792. SYSTEMTIME t;
  13793. Zero(&t, sizeof(t));
  13794. t.wYear = a;
  13795. t.wMonth = b;
  13796. t.wDay = c;
  13797. t.wHour = d;
  13798. t.wMinute = e;
  13799. t.wSecond = f;
  13800. ret = SystemToUINT64(&t);
  13801. }
  13802. FreeToken(t);
  13803. return ret;
  13804. }
  13805. // Evaluate the date and time string
  13806. bool CmdEvalDateTime(CONSOLE *c, wchar_t *str, void *param)
  13807. {
  13808. UINT64 ret;
  13809. char tmp[MAX_SIZE];
  13810. // Validate arguments
  13811. if (c == NULL || str == NULL)
  13812. {
  13813. return false;
  13814. }
  13815. UniToStr(tmp, sizeof(tmp), str);
  13816. ret = StrToDateTime64(tmp);
  13817. if (ret == INFINITE)
  13818. {
  13819. c->Write(c, _UU("CMD_EVAL_DATE_TIME_FAILED"));
  13820. return false;
  13821. }
  13822. return true;
  13823. }
  13824. // Set the expiration date of the user
  13825. UINT PsUserExpiresSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13826. {
  13827. LIST *o;
  13828. PS *ps = (PS *)param;
  13829. UINT ret = 0;
  13830. RPC_SET_USER t;
  13831. UINT64 expires;
  13832. // Parameter list that can be specified
  13833. PARAM args[] =
  13834. {
  13835. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13836. {"[name]", CmdPrompt, _UU("CMD_UserCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13837. {"EXPIRES", CmdPrompt, _UU("CMD_UserExpiresSet_Prompt_EXPIRES"), CmdEvalDateTime, NULL},
  13838. };
  13839. // If virtual HUB is not selected, it's an error
  13840. if (ps->HubName == NULL)
  13841. {
  13842. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13843. return ERR_INVALID_PARAMETER;
  13844. }
  13845. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13846. if (o == NULL)
  13847. {
  13848. return ERR_INVALID_PARAMETER;
  13849. }
  13850. Zero(&t, sizeof(t));
  13851. // Get the user object
  13852. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13853. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13854. ret = ScGetUser(ps->Rpc, &t);
  13855. if (ret != ERR_NO_ERROR)
  13856. {
  13857. // An error has occured
  13858. CmdPrintError(c, ret);
  13859. FreeParamValueList(o);
  13860. return ret;
  13861. }
  13862. // Update the information
  13863. expires = StrToDateTime64(GetParamStr(o, "EXPIRES"));
  13864. if (expires != 0)
  13865. {
  13866. expires = LocalToSystem64(expires);
  13867. }
  13868. t.ExpireTime = expires;
  13869. // Write the user object
  13870. ret = ScSetUser(ps->Rpc, &t);
  13871. if (ret != ERR_NO_ERROR)
  13872. {
  13873. // An error has occured
  13874. CmdPrintError(c, ret);
  13875. FreeParamValueList(o);
  13876. return ret;
  13877. }
  13878. FreeRpcSetUser(&t);
  13879. FreeParamValueList(o);
  13880. return 0;
  13881. }
  13882. // Get the group list
  13883. UINT PsGroupList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13884. {
  13885. LIST *o;
  13886. PS *ps = (PS *)param;
  13887. UINT ret = 0;
  13888. RPC_ENUM_GROUP t;
  13889. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  13890. if (o == NULL)
  13891. {
  13892. return ERR_INVALID_PARAMETER;
  13893. }
  13894. // If virtual HUB is not selected, it's an error
  13895. if (ps->HubName == NULL)
  13896. {
  13897. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13898. return ERR_INVALID_PARAMETER;
  13899. }
  13900. Zero(&t, sizeof(t));
  13901. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13902. // RPC call
  13903. ret = ScEnumGroup(ps->Rpc, &t);
  13904. if (ret != ERR_NO_ERROR)
  13905. {
  13906. // An error has occured
  13907. CmdPrintError(c, ret);
  13908. FreeParamValueList(o);
  13909. return ret;
  13910. }
  13911. else
  13912. {
  13913. CT *ct = CtNew();
  13914. UINT i;
  13915. CtInsertColumn(ct, _UU("SM_GROUPLIST_NAME"), false);
  13916. CtInsertColumn(ct, _UU("SM_GROUPLIST_REALNAME"), false);
  13917. CtInsertColumn(ct, _UU("SM_GROUPLIST_NOTE"), false);
  13918. CtInsertColumn(ct, _UU("SM_GROUPLIST_NUMUSERS"), false);
  13919. for (i = 0;i < t.NumGroup;i++)
  13920. {
  13921. wchar_t tmp1[MAX_SIZE];
  13922. wchar_t tmp2[MAX_SIZE];
  13923. RPC_ENUM_GROUP_ITEM *e = &t.Groups[i];
  13924. StrToUni(tmp1, sizeof(tmp1), e->Name);
  13925. UniToStru(tmp2, e->NumUsers);
  13926. CtInsert(ct, tmp1, e->Realname, e->Note, tmp2);
  13927. }
  13928. CtFreeEx(ct, c, true);
  13929. }
  13930. FreeRpcEnumGroup(&t);
  13931. FreeParamValueList(o);
  13932. return 0;
  13933. }
  13934. // Create a group
  13935. UINT PsGroupCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13936. {
  13937. LIST *o;
  13938. PS *ps = (PS *)param;
  13939. UINT ret = 0;
  13940. RPC_SET_GROUP t;
  13941. // Parameter list that can be specified
  13942. PARAM args[] =
  13943. {
  13944. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13945. {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13946. {"REALNAME", CmdPrompt, _UU("CMD_GroupCreate_Prompt_REALNAME"), NULL, NULL},
  13947. {"NOTE", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NOTE"), NULL, NULL},
  13948. };
  13949. // If virtual HUB is not selected, it's an error
  13950. if (ps->HubName == NULL)
  13951. {
  13952. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13953. return ERR_INVALID_PARAMETER;
  13954. }
  13955. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  13956. if (o == NULL)
  13957. {
  13958. return ERR_INVALID_PARAMETER;
  13959. }
  13960. Zero(&t, sizeof(t));
  13961. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  13962. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  13963. UniStrCpy(t.Realname, sizeof(t.Realname), GetParamUniStr(o, "REALNAME"));
  13964. UniStrCpy(t.Note, sizeof(t.Note), GetParamUniStr(o, "NOTE"));
  13965. // RPC call
  13966. ret = ScCreateGroup(ps->Rpc, &t);
  13967. if (ret != ERR_NO_ERROR)
  13968. {
  13969. // An error has occured
  13970. CmdPrintError(c, ret);
  13971. FreeParamValueList(o);
  13972. return ret;
  13973. }
  13974. FreeRpcSetGroup(&t);
  13975. FreeParamValueList(o);
  13976. return 0;
  13977. }
  13978. // Set the group information
  13979. UINT PsGroupSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  13980. {
  13981. LIST *o;
  13982. PS *ps = (PS *)param;
  13983. UINT ret = 0;
  13984. RPC_SET_GROUP t;
  13985. // Parameter list that can be specified
  13986. PARAM args[] =
  13987. {
  13988. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  13989. {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  13990. {"REALNAME", CmdPrompt, _UU("CMD_GroupCreate_Prompt_REALNAME"), NULL, NULL},
  13991. {"NOTE", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NOTE"), NULL, NULL},
  13992. };
  13993. // If virtual HUB is not selected, it's an error
  13994. if (ps->HubName == NULL)
  13995. {
  13996. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  13997. return ERR_INVALID_PARAMETER;
  13998. }
  13999. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14000. if (o == NULL)
  14001. {
  14002. return ERR_INVALID_PARAMETER;
  14003. }
  14004. Zero(&t, sizeof(t));
  14005. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14006. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  14007. // RPC call
  14008. ret = ScGetGroup(ps->Rpc, &t);
  14009. if (ret != ERR_NO_ERROR)
  14010. {
  14011. // An error has occured
  14012. CmdPrintError(c, ret);
  14013. FreeParamValueList(o);
  14014. return ret;
  14015. }
  14016. // Information update
  14017. UniStrCpy(t.Realname, sizeof(t.Realname), GetParamUniStr(o, "REALNAME"));
  14018. UniStrCpy(t.Note, sizeof(t.Note), GetParamUniStr(o, "NOTE"));
  14019. // RPC call
  14020. ret = ScSetGroup(ps->Rpc, &t);
  14021. if (ret != ERR_NO_ERROR)
  14022. {
  14023. // An error has occured
  14024. CmdPrintError(c, ret);
  14025. FreeParamValueList(o);
  14026. return ret;
  14027. }
  14028. FreeRpcSetGroup(&t);
  14029. FreeParamValueList(o);
  14030. return 0;
  14031. }
  14032. // Delete a group
  14033. UINT PsGroupDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14034. {
  14035. LIST *o;
  14036. PS *ps = (PS *)param;
  14037. UINT ret = 0;
  14038. RPC_DELETE_USER t;
  14039. // Parameter list that can be specified
  14040. PARAM args[] =
  14041. {
  14042. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  14043. {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  14044. };
  14045. // If virtual HUB is not selected, it's an error
  14046. if (ps->HubName == NULL)
  14047. {
  14048. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14049. return ERR_INVALID_PARAMETER;
  14050. }
  14051. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14052. if (o == NULL)
  14053. {
  14054. return ERR_INVALID_PARAMETER;
  14055. }
  14056. Zero(&t, sizeof(t));
  14057. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14058. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  14059. // RPC call
  14060. ret = ScDeleteGroup(ps->Rpc, &t);
  14061. if (ret != ERR_NO_ERROR)
  14062. {
  14063. // An error has occured
  14064. CmdPrintError(c, ret);
  14065. FreeParamValueList(o);
  14066. return ret;
  14067. }
  14068. FreeParamValueList(o);
  14069. return 0;
  14070. }
  14071. // Get the group information and the list of users who belong to the group
  14072. UINT PsGroupGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14073. {
  14074. LIST *o;
  14075. PS *ps = (PS *)param;
  14076. UINT ret = 0;
  14077. RPC_SET_GROUP t;
  14078. // Parameter list that can be specified
  14079. PARAM args[] =
  14080. {
  14081. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  14082. {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  14083. };
  14084. // If virtual HUB is not selected, it's an error
  14085. if (ps->HubName == NULL)
  14086. {
  14087. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14088. return ERR_INVALID_PARAMETER;
  14089. }
  14090. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14091. if (o == NULL)
  14092. {
  14093. return ERR_INVALID_PARAMETER;
  14094. }
  14095. Zero(&t, sizeof(t));
  14096. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14097. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  14098. // RPC call
  14099. ret = ScGetGroup(ps->Rpc, &t);
  14100. if (ret != ERR_NO_ERROR)
  14101. {
  14102. // An error has occured
  14103. CmdPrintError(c, ret);
  14104. FreeParamValueList(o);
  14105. return ret;
  14106. }
  14107. else
  14108. {
  14109. wchar_t tmp[MAX_SIZE];
  14110. char groupname[MAX_USERNAME_LEN + 1];
  14111. CT *ct = CtNewStandard();
  14112. StrCpy(groupname, sizeof(groupname), t.Name);
  14113. StrToUni(tmp, sizeof(tmp), t.Name);
  14114. CtInsert(ct, _UU("CMD_GroupGet_Column_NAME"), tmp);
  14115. CtInsert(ct, _UU("CMD_GroupGet_Column_REALNAME"), t.Realname);
  14116. CtInsert(ct, _UU("CMD_GroupGet_Column_NOTE"), t.Note);
  14117. CtFree(ct, c);
  14118. if (t.Policy != NULL)
  14119. {
  14120. c->Write(c, L"");
  14121. c->Write(c, _UU("CMD_GroupGet_Column_POLICY"));
  14122. PrintPolicy(c, t.Policy, false);
  14123. }
  14124. {
  14125. RPC_ENUM_USER t;
  14126. bool b = false;
  14127. Zero(&t, sizeof(t));
  14128. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14129. if (ScEnumUser(ps->Rpc, &t) == ERR_NO_ERROR)
  14130. {
  14131. UINT i;
  14132. for (i = 0;i < t.NumUser;i++)
  14133. {
  14134. RPC_ENUM_USER_ITEM *u = &t.Users[i];
  14135. if (StrCmpi(u->GroupName, groupname) == 0)
  14136. {
  14137. if (b == false)
  14138. {
  14139. b = true;
  14140. c->Write(c, L"");
  14141. c->Write(c, _UU("CMD_GroupGet_Column_MEMBERS"));
  14142. }
  14143. UniFormat(tmp, sizeof(tmp), L" %S", u->Name);
  14144. c->Write(c, tmp);
  14145. }
  14146. }
  14147. FreeRpcEnumUser(&t);
  14148. if (b)
  14149. {
  14150. c->Write(c, L"");
  14151. }
  14152. }
  14153. }
  14154. }
  14155. FreeRpcSetGroup(&t);
  14156. FreeParamValueList(o);
  14157. return 0;
  14158. }
  14159. // Add an user to the group
  14160. UINT PsGroupJoin(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14161. {
  14162. LIST *o;
  14163. PS *ps = (PS *)param;
  14164. UINT ret = 0;
  14165. RPC_SET_USER t;
  14166. // Parameter list that can be specified
  14167. PARAM args[] =
  14168. {
  14169. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  14170. {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  14171. {"USERNAME", CmdPrompt, _UU("CMD_GroupJoin_Prompt_USERNAME"), CmdEvalNotEmpty, NULL},
  14172. };
  14173. // If virtual HUB is not selected, it's an error
  14174. if (ps->HubName == NULL)
  14175. {
  14176. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14177. return ERR_INVALID_PARAMETER;
  14178. }
  14179. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14180. if (o == NULL)
  14181. {
  14182. return ERR_INVALID_PARAMETER;
  14183. }
  14184. Zero(&t, sizeof(t));
  14185. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14186. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "USERNAME"));
  14187. // RPC call
  14188. ret = ScGetUser(ps->Rpc, &t);
  14189. if (ret != ERR_NO_ERROR)
  14190. {
  14191. // An error has occured
  14192. CmdPrintError(c, ret);
  14193. FreeParamValueList(o);
  14194. return ret;
  14195. }
  14196. else
  14197. {
  14198. // Update the Group
  14199. StrCpy(t.GroupName, sizeof(t.GroupName), GetParamStr(o, "[name]"));
  14200. ret = ScSetUser(ps->Rpc, &t);
  14201. if (ret != ERR_NO_ERROR)
  14202. {
  14203. // An error has occured
  14204. CmdPrintError(c, ret);
  14205. FreeParamValueList(o);
  14206. return ret;
  14207. }
  14208. }
  14209. FreeRpcSetUser(&t);
  14210. FreeParamValueList(o);
  14211. return 0;
  14212. }
  14213. // Delete the user from a group
  14214. UINT PsGroupUnjoin(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14215. {
  14216. LIST *o;
  14217. PS *ps = (PS *)param;
  14218. UINT ret = 0;
  14219. RPC_SET_USER t;
  14220. // Parameter list that can be specified
  14221. PARAM args[] =
  14222. {
  14223. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  14224. {"[name]", CmdPrompt, _UU("CMD_GroupUnjoin_Prompt_name"), CmdEvalNotEmpty, NULL},
  14225. };
  14226. // If virtual HUB is not selected, it's an error
  14227. if (ps->HubName == NULL)
  14228. {
  14229. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14230. return ERR_INVALID_PARAMETER;
  14231. }
  14232. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14233. if (o == NULL)
  14234. {
  14235. return ERR_INVALID_PARAMETER;
  14236. }
  14237. Zero(&t, sizeof(t));
  14238. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14239. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  14240. // RPC call
  14241. ret = ScGetUser(ps->Rpc, &t);
  14242. if (ret != ERR_NO_ERROR)
  14243. {
  14244. // An error has occured
  14245. CmdPrintError(c, ret);
  14246. FreeParamValueList(o);
  14247. return ret;
  14248. }
  14249. else
  14250. {
  14251. // Update the Group
  14252. StrCpy(t.GroupName, sizeof(t.GroupName), "");
  14253. ret = ScSetUser(ps->Rpc, &t);
  14254. if (ret != ERR_NO_ERROR)
  14255. {
  14256. // An error has occured
  14257. CmdPrintError(c, ret);
  14258. FreeParamValueList(o);
  14259. return ret;
  14260. }
  14261. }
  14262. FreeRpcSetUser(&t);
  14263. FreeParamValueList(o);
  14264. return 0;
  14265. }
  14266. // Delete the security policy of the group
  14267. UINT PsGroupPolicyRemove(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14268. {
  14269. LIST *o;
  14270. PS *ps = (PS *)param;
  14271. UINT ret = 0;
  14272. RPC_SET_GROUP t;
  14273. // Parameter list that can be specified
  14274. PARAM args[] =
  14275. {
  14276. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  14277. {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  14278. };
  14279. // If virtual HUB is not selected, it's an error
  14280. if (ps->HubName == NULL)
  14281. {
  14282. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14283. return ERR_INVALID_PARAMETER;
  14284. }
  14285. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14286. if (o == NULL)
  14287. {
  14288. return ERR_INVALID_PARAMETER;
  14289. }
  14290. Zero(&t, sizeof(t));
  14291. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14292. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  14293. // RPC call
  14294. ret = ScGetGroup(ps->Rpc, &t);
  14295. if (ret != ERR_NO_ERROR)
  14296. {
  14297. // An error has occured
  14298. CmdPrintError(c, ret);
  14299. FreeParamValueList(o);
  14300. return ret;
  14301. }
  14302. else
  14303. {
  14304. // Update
  14305. if (t.Policy != NULL)
  14306. {
  14307. Free(t.Policy);
  14308. t.Policy = NULL;
  14309. }
  14310. ret = ScSetGroup(ps->Rpc, &t);
  14311. if (ret != ERR_NO_ERROR)
  14312. {
  14313. // An error has occured
  14314. CmdPrintError(c, ret);
  14315. FreeParamValueList(o);
  14316. return ret;
  14317. }
  14318. }
  14319. FreeRpcSetGroup(&t);
  14320. FreeParamValueList(o);
  14321. return 0;
  14322. }
  14323. // Set a security policy to a group
  14324. UINT PsGroupPolicySet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14325. {
  14326. LIST *o;
  14327. PS *ps = (PS *)param;
  14328. UINT ret = 0;
  14329. RPC_SET_GROUP t;
  14330. // Parameter list that can be specified
  14331. PARAM args[] =
  14332. {
  14333. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  14334. {"[name]", CmdPrompt, _UU("CMD_GroupCreate_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  14335. {"NAME", CmdPrompt, _UU("CMD_CascadePolicySet_PROMPT_POLNAME"), CmdEvalNotEmpty, NULL},
  14336. {"VALUE", CmdPrompt, _UU("CMD_CascadePolicySet_PROMPT_POLVALUE"), CmdEvalNotEmpty, NULL},
  14337. };
  14338. // If virtual HUB is not selected, it's an error
  14339. if (ps->HubName == NULL)
  14340. {
  14341. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14342. return ERR_INVALID_PARAMETER;
  14343. }
  14344. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14345. if (o == NULL)
  14346. {
  14347. return ERR_INVALID_PARAMETER;
  14348. }
  14349. Zero(&t, sizeof(t));
  14350. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14351. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  14352. // RPC call
  14353. ret = ScGetGroup(ps->Rpc, &t);
  14354. if (ret != ERR_NO_ERROR)
  14355. {
  14356. // An error has occured
  14357. CmdPrintError(c, ret);
  14358. FreeParamValueList(o);
  14359. return ret;
  14360. }
  14361. else
  14362. {
  14363. // Update
  14364. if (t.Policy == NULL)
  14365. {
  14366. t.Policy = ClonePolicy(GetDefaultPolicy());
  14367. }
  14368. if (EditPolicy(c, t.Policy, GetParamStr(o, "NAME"), GetParamStr(o, "VALUE"), false) == false)
  14369. {
  14370. // An error has occured
  14371. FreeRpcSetGroup(&t);
  14372. CmdPrintError(c, ret);
  14373. FreeParamValueList(o);
  14374. return ERR_INTERNAL_ERROR;
  14375. }
  14376. ret = ScSetGroup(ps->Rpc, &t);
  14377. if (ret != ERR_NO_ERROR)
  14378. {
  14379. // An error has occured
  14380. CmdPrintError(c, ret);
  14381. FreeParamValueList(o);
  14382. return ret;
  14383. }
  14384. }
  14385. FreeRpcSetGroup(&t);
  14386. FreeParamValueList(o);
  14387. return 0;
  14388. }
  14389. // Get the connected session list
  14390. UINT PsSessionList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14391. {
  14392. LIST *o;
  14393. PS *ps = (PS *)param;
  14394. UINT ret = 0;
  14395. RPC_ENUM_SESSION t;
  14396. UINT server_type = 0;
  14397. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  14398. if (o == NULL)
  14399. {
  14400. return ERR_INVALID_PARAMETER;
  14401. }
  14402. // If virtual HUB is not selected, it's an error
  14403. if (ps->HubName == NULL)
  14404. {
  14405. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14406. return ERR_INVALID_PARAMETER;
  14407. }
  14408. {
  14409. // Get the server type
  14410. RPC_SERVER_INFO t;
  14411. Zero(&t, sizeof(t));
  14412. if (ScGetServerInfo(ps->Rpc, &t) == ERR_NO_ERROR)
  14413. {
  14414. server_type = t.ServerType;
  14415. FreeRpcServerInfo(&t);
  14416. }
  14417. }
  14418. Zero(&t, sizeof(t));
  14419. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14420. // RPC call
  14421. ret = ScEnumSession(ps->Rpc, &t);
  14422. if (ret != ERR_NO_ERROR)
  14423. {
  14424. // An error has occured
  14425. CmdPrintError(c, ret);
  14426. FreeParamValueList(o);
  14427. return ret;
  14428. }
  14429. else
  14430. {
  14431. CT *ct = CtNew();
  14432. UINT i;
  14433. CtInsertColumn(ct, _UU("SM_SESS_COLUMN_1"), false);
  14434. CtInsertColumn(ct, _UU("SM_SESS_COLUMN_8"), false);
  14435. CtInsertColumn(ct, _UU("SM_SESS_COLUMN_2"), false);
  14436. CtInsertColumn(ct, _UU("SM_SESS_COLUMN_3"), false);
  14437. CtInsertColumn(ct, _UU("SM_SESS_COLUMN_4"), false);
  14438. CtInsertColumn(ct, _UU("SM_SESS_COLUMN_5"), true);
  14439. CtInsertColumn(ct, _UU("SM_SESS_COLUMN_6"), true);
  14440. CtInsertColumn(ct, _UU("SM_SESS_COLUMN_7"), true);
  14441. for (i = 0;i < t.NumSession;i++)
  14442. {
  14443. RPC_ENUM_SESSION_ITEM *e = &t.Sessions[i];
  14444. wchar_t tmp1[MAX_SIZE];
  14445. wchar_t *tmp2;
  14446. wchar_t tmp3[MAX_SIZE];
  14447. wchar_t tmp4[MAX_SIZE];
  14448. wchar_t tmp5[MAX_SIZE];
  14449. wchar_t tmp6[MAX_SIZE];
  14450. wchar_t tmp7[MAX_SIZE];
  14451. wchar_t tmp8[MAX_SIZE];
  14452. bool free_tmp2 = false;
  14453. StrToUni(tmp1, sizeof(tmp1), e->Name);
  14454. tmp2 = _UU("SM_SESS_NORMAL");
  14455. if (server_type != SERVER_TYPE_STANDALONE)
  14456. {
  14457. if (e->RemoteSession)
  14458. {
  14459. tmp2 = ZeroMalloc(MAX_SIZE);
  14460. UniFormat(tmp2, MAX_SIZE, _UU("SM_SESS_REMOTE"), e->RemoteHostname);
  14461. free_tmp2 = true;
  14462. }
  14463. else
  14464. {
  14465. if (StrLen(e->RemoteHostname) == 0)
  14466. {
  14467. tmp2 = _UU("SM_SESS_LOCAL");
  14468. }
  14469. else
  14470. {
  14471. tmp2 = ZeroMalloc(MAX_SIZE);
  14472. UniFormat(tmp2, MAX_SIZE, _UU("SM_SESS_LOCAL_2"), e->RemoteHostname);
  14473. free_tmp2 = true;
  14474. }
  14475. }
  14476. }
  14477. if (e->LinkMode)
  14478. {
  14479. if (free_tmp2)
  14480. {
  14481. Free(tmp2);
  14482. free_tmp2 = false;
  14483. }
  14484. tmp2 = _UU("SM_SESS_LINK");
  14485. }
  14486. else if (e->SecureNATMode)
  14487. {
  14488. /*if (free_tmp2)
  14489. {
  14490. Free(tmp2);
  14491. free_tmp2 = false;
  14492. }*/
  14493. tmp2 = _UU("SM_SESS_SNAT");
  14494. }
  14495. StrToUni(tmp3, sizeof(tmp3), e->Username);
  14496. StrToUni(tmp4, sizeof(tmp4), e->Hostname);
  14497. if (e->LinkMode)
  14498. {
  14499. UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_SESS_LINK_HOSTNAME"));
  14500. }
  14501. else if (e->SecureNATMode)
  14502. {
  14503. UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_SESS_SNAT_HOSTNAME"));
  14504. }
  14505. else if (e->BridgeMode)
  14506. {
  14507. UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_SESS_BRIDGE_HOSTNAME"));
  14508. }
  14509. else if (StartWith(e->Username, L3_USERNAME))
  14510. {
  14511. UniStrCpy(tmp4, sizeof(tmp4), _UU("SM_SESS_LAYER3_HOSTNAME"));
  14512. }
  14513. UniFormat(tmp5, sizeof(tmp5), L"%u / %u", e->CurrentNumTcp, e->MaxNumTcp);
  14514. if (e->LinkMode)
  14515. {
  14516. UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_SESS_LINK_TCP"));
  14517. }
  14518. else if (e->SecureNATMode)
  14519. {
  14520. UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_SESS_SNAT_TCP"));
  14521. }
  14522. else if (e->BridgeMode)
  14523. {
  14524. UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_SESS_BRIDGE_TCP"));
  14525. }
  14526. UniToStr3(tmp6, sizeof(tmp6), e->PacketSize);
  14527. UniToStr3(tmp7, sizeof(tmp7), e->PacketNum);
  14528. if (e->VLanId == 0)
  14529. {
  14530. UniStrCpy(tmp8, sizeof(tmp8), _UU("CM_ST_NO_VLAN"));
  14531. }
  14532. else
  14533. {
  14534. UniToStru(tmp8, e->VLanId);
  14535. }
  14536. CtInsert(ct, tmp1, tmp8, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7);
  14537. if (free_tmp2)
  14538. {
  14539. Free(tmp2);
  14540. }
  14541. }
  14542. CtFreeEx(ct, c, true);
  14543. }
  14544. FreeRpcEnumSession(&t);
  14545. FreeParamValueList(o);
  14546. return 0;
  14547. }
  14548. // Display the NODE_INFO
  14549. void CmdPrintNodeInfo(CT *ct, NODE_INFO *info)
  14550. {
  14551. wchar_t tmp[MAX_SIZE];
  14552. char str[MAX_SIZE];
  14553. // Validate arguments
  14554. if (ct == NULL || info == NULL)
  14555. {
  14556. return;
  14557. }
  14558. StrToUni(tmp, sizeof(tmp), info->ClientProductName);
  14559. CtInsert(ct, _UU("SM_NODE_CLIENT_NAME"), tmp);
  14560. UniFormat(tmp, sizeof(tmp), L"%u.%02u", Endian32(info->ClientProductVer) / 100, Endian32(info->ClientProductVer) % 100);
  14561. CtInsert(ct, _UU("SM_NODE_CLIENT_VER"), tmp);
  14562. UniFormat(tmp, sizeof(tmp), L"Build %u", Endian32(info->ClientProductBuild));
  14563. CtInsert(ct, _UU("SM_NODE_CLIENT_BUILD"), tmp);
  14564. StrToUni(tmp, sizeof(tmp), info->ClientOsName);
  14565. CtInsert(ct, _UU("SM_NODE_CLIENT_OS_NAME"), tmp);
  14566. StrToUni(tmp, sizeof(tmp), info->ClientOsVer);
  14567. CtInsert(ct, _UU("SM_NODE_CLIENT_OS_VER"), tmp);
  14568. StrToUni(tmp, sizeof(tmp), info->ClientOsProductId);
  14569. CtInsert(ct, _UU("SM_NODE_CLIENT_OS_PID"), tmp);
  14570. StrToUni(tmp, sizeof(tmp), info->ClientHostname);
  14571. CtInsert(ct, _UU("SM_NODE_CLIENT_HOST"), tmp);
  14572. IPToStr4or6(str, sizeof(str), info->ClientIpAddress, info->ClientIpAddress6);
  14573. StrToUni(tmp, sizeof(tmp), str);
  14574. CtInsert(ct, _UU("SM_NODE_CLIENT_IP"), tmp);
  14575. UniToStru(tmp, Endian32(info->ClientPort));
  14576. CtInsert(ct, _UU("SM_NODE_CLIENT_PORT"), tmp);
  14577. StrToUni(tmp, sizeof(tmp), info->ServerHostname);
  14578. CtInsert(ct, _UU("SM_NODE_SERVER_HOST"), tmp);
  14579. IPToStr4or6(str, sizeof(str), info->ServerIpAddress, info->ServerIpAddress6);
  14580. StrToUni(tmp, sizeof(tmp), str);
  14581. CtInsert(ct, _UU("SM_NODE_SERVER_IP"), tmp);
  14582. UniToStru(tmp, Endian32(info->ServerPort));
  14583. CtInsert(ct, _UU("SM_NODE_SERVER_PORT"), tmp);
  14584. if (StrLen(info->ProxyHostname) != 0)
  14585. {
  14586. StrToUni(tmp, sizeof(tmp), info->ProxyHostname);
  14587. CtInsert(ct, _UU("SM_NODE_PROXY_HOSTNAME"), tmp);
  14588. IPToStr4or6(str, sizeof(str), info->ProxyIpAddress, info->ProxyIpAddress6);
  14589. StrToUni(tmp, sizeof(tmp), str);
  14590. CtInsert(ct, _UU("SM_NODE_PROXY_IP"), tmp);
  14591. UniToStru(tmp, Endian32(info->ProxyPort));
  14592. CtInsert(ct, _UU("SM_NODE_PROXY_PORT"), tmp);
  14593. }
  14594. }
  14595. // Get the session information
  14596. UINT PsSessionGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14597. {
  14598. LIST *o;
  14599. PS *ps = (PS *)param;
  14600. UINT ret = 0;
  14601. RPC_SESSION_STATUS t;
  14602. // Parameter list that can be specified
  14603. PARAM args[] =
  14604. {
  14605. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  14606. {"[name]", CmdPrompt, _UU("CMD_SessionGet_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  14607. };
  14608. // If virtual HUB is not selected, it's an error
  14609. if (ps->HubName == NULL)
  14610. {
  14611. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14612. return ERR_INVALID_PARAMETER;
  14613. }
  14614. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14615. if (o == NULL)
  14616. {
  14617. return ERR_INVALID_PARAMETER;
  14618. }
  14619. Zero(&t, sizeof(t));
  14620. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14621. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  14622. // RPC call
  14623. ret = ScGetSessionStatus(ps->Rpc, &t);
  14624. if (ret != ERR_NO_ERROR)
  14625. {
  14626. // An error has occured
  14627. CmdPrintError(c, ret);
  14628. FreeParamValueList(o);
  14629. return ret;
  14630. }
  14631. else
  14632. {
  14633. wchar_t tmp[MAX_SIZE];
  14634. char str[MAX_SIZE];
  14635. CT *ct = CtNewStandard();
  14636. if (t.ClientIp != 0)
  14637. {
  14638. IPToStr4or6(str, sizeof(str), t.ClientIp, t.ClientIp6);
  14639. StrToUni(tmp, sizeof(tmp), str);
  14640. CtInsert(ct, _UU("SM_CLIENT_IP"), tmp);
  14641. }
  14642. if (StrLen(t.ClientHostName) != 0)
  14643. {
  14644. StrToUni(tmp, sizeof(tmp), t.ClientHostName);
  14645. CtInsert(ct, _UU("SM_CLIENT_HOSTNAME"), tmp);
  14646. }
  14647. StrToUni(tmp, sizeof(tmp), t.Username);
  14648. CtInsert(ct, _UU("SM_SESS_STATUS_USERNAME"), tmp);
  14649. if (StrCmpi(t.Username, LINK_USER_NAME_PRINT) != 0 && StrCmpi(t.Username, SNAT_USER_NAME_PRINT) != 0 && StrCmpi(t.Username, BRIDGE_USER_NAME_PRINT) != 0)
  14650. {
  14651. StrToUni(tmp, sizeof(tmp), t.RealUsername);
  14652. CtInsert(ct, _UU("SM_SESS_STATUS_REALUSER"), tmp);
  14653. }
  14654. if (IsEmptyStr(t.GroupName) == false)
  14655. {
  14656. StrToUni(tmp, sizeof(tmp), t.GroupName);
  14657. CtInsert(ct, _UU("SM_SESS_STATUS_GROUPNAME"), tmp);
  14658. }
  14659. CmdPrintStatusToListViewEx(ct, &t.Status, true);
  14660. if (StrCmpi(t.Username, LINK_USER_NAME_PRINT) != 0 && StrCmpi(t.Username, SNAT_USER_NAME_PRINT) != 0 && StrCmpi(t.Username, BRIDGE_USER_NAME_PRINT) != 0 &&
  14661. StartWith(t.Username, L3_USERNAME) == false)
  14662. {
  14663. CmdPrintNodeInfo(ct, &t.NodeInfo);
  14664. }
  14665. CtFree(ct, c);
  14666. }
  14667. FreeRpcSessionStatus(&t);
  14668. FreeParamValueList(o);
  14669. return 0;
  14670. }
  14671. // Disconnect the session
  14672. UINT PsSessionDisconnect(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14673. {
  14674. LIST *o;
  14675. PS *ps = (PS *)param;
  14676. UINT ret = 0;
  14677. RPC_DELETE_SESSION t;
  14678. // Parameter list that can be specified
  14679. PARAM args[] =
  14680. {
  14681. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  14682. {"[name]", CmdPrompt, _UU("CMD_SessionGet_Prompt_NAME"), CmdEvalNotEmpty, NULL},
  14683. };
  14684. // If virtual HUB is not selected, it's an error
  14685. if (ps->HubName == NULL)
  14686. {
  14687. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14688. return ERR_INVALID_PARAMETER;
  14689. }
  14690. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14691. if (o == NULL)
  14692. {
  14693. return ERR_INVALID_PARAMETER;
  14694. }
  14695. Zero(&t, sizeof(t));
  14696. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14697. StrCpy(t.Name, sizeof(t.Name), GetParamStr(o, "[name]"));
  14698. // RPC call
  14699. ret = ScDeleteSession(ps->Rpc, &t);
  14700. if (ret != ERR_NO_ERROR)
  14701. {
  14702. // An error has occured
  14703. CmdPrintError(c, ret);
  14704. FreeParamValueList(o);
  14705. return ret;
  14706. }
  14707. FreeParamValueList(o);
  14708. return 0;
  14709. }
  14710. // Get the MAC address table database
  14711. UINT PsMacTable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14712. {
  14713. LIST *o;
  14714. PS *ps = (PS *)param;
  14715. UINT ret = 0;
  14716. RPC_ENUM_MAC_TABLE t;
  14717. UINT i;
  14718. // Parameter list that can be specified
  14719. PARAM args[] =
  14720. {
  14721. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  14722. {"[session_name]", NULL, NULL, NULL, NULL,}
  14723. };
  14724. // If virtual HUB is not selected, it's an error
  14725. if (ps->HubName == NULL)
  14726. {
  14727. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14728. return ERR_INVALID_PARAMETER;
  14729. }
  14730. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14731. if (o == NULL)
  14732. {
  14733. return ERR_INVALID_PARAMETER;
  14734. }
  14735. Zero(&t, sizeof(t));
  14736. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14737. // RPC call
  14738. ret = ScEnumMacTable(ps->Rpc, &t);
  14739. if (ret != ERR_NO_ERROR)
  14740. {
  14741. // An error has occured
  14742. CmdPrintError(c, ret);
  14743. FreeParamValueList(o);
  14744. return ret;
  14745. }
  14746. else
  14747. {
  14748. CT *ct = CtNew();
  14749. char *session_name = GetParamStr(o, "[session_name]");
  14750. if (IsEmptyStr(session_name))
  14751. {
  14752. session_name = NULL;
  14753. }
  14754. CtInsertColumn(ct, _UU("CMD_ID"), false);
  14755. CtInsertColumn(ct, _UU("SM_MAC_COLUMN_1"), false);
  14756. CtInsertColumn(ct, _UU("SM_MAC_COLUMN_1A"), false);
  14757. CtInsertColumn(ct, _UU("SM_MAC_COLUMN_2"), false);
  14758. CtInsertColumn(ct, _UU("SM_MAC_COLUMN_3"), false);
  14759. CtInsertColumn(ct, _UU("SM_MAC_COLUMN_4"), false);
  14760. CtInsertColumn(ct, _UU("SM_MAC_COLUMN_5"), false);
  14761. for (i = 0;i < t.NumMacTable;i++)
  14762. {
  14763. char str[MAX_SIZE];
  14764. wchar_t tmp0[128];
  14765. wchar_t tmp1[MAX_SIZE];
  14766. wchar_t tmp2[MAX_SIZE];
  14767. wchar_t tmp3[MAX_SIZE];
  14768. wchar_t tmp4[MAX_SIZE];
  14769. wchar_t tmp5[MAX_SIZE];
  14770. wchar_t tmp6[MAX_SIZE];
  14771. RPC_ENUM_MAC_TABLE_ITEM *e = &t.MacTables[i];
  14772. if (session_name == NULL || StrCmpi(e->SessionName, session_name) == 0)
  14773. {
  14774. UniToStru(tmp0, e->Key);
  14775. StrToUni(tmp1, sizeof(tmp1), e->SessionName);
  14776. MacToStr(str, sizeof(str), e->MacAddress);
  14777. StrToUni(tmp2, sizeof(tmp2), str);
  14778. GetDateTimeStr64Uni(tmp3, sizeof(tmp3), SystemToLocal64(e->CreatedTime));
  14779. GetDateTimeStr64Uni(tmp4, sizeof(tmp4), SystemToLocal64(e->UpdatedTime));
  14780. if (StrLen(e->RemoteHostname) == 0)
  14781. {
  14782. UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_MACIP_LOCAL"));
  14783. }
  14784. else
  14785. {
  14786. UniFormat(tmp5, sizeof(tmp5), _UU("SM_MACIP_SERVER"), e->RemoteHostname);
  14787. }
  14788. UniToStru(tmp6, e->VlanId);
  14789. if (e->VlanId == 0)
  14790. {
  14791. UniStrCpy(tmp6, sizeof(tmp6), _UU("CM_ST_NONE"));
  14792. }
  14793. CtInsert(ct,
  14794. tmp0, tmp1, tmp6, tmp2, tmp3, tmp4, tmp5);
  14795. }
  14796. }
  14797. CtFreeEx(ct, c, true);
  14798. }
  14799. FreeRpcEnumMacTable(&t);
  14800. FreeParamValueList(o);
  14801. return 0;
  14802. }
  14803. // Delete a MAC address table entry
  14804. UINT PsMacDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14805. {
  14806. LIST *o;
  14807. PS *ps = (PS *)param;
  14808. UINT ret = 0;
  14809. RPC_DELETE_TABLE t;
  14810. // Parameter list that can be specified
  14811. PARAM args[] =
  14812. {
  14813. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  14814. {"[id]", CmdPrompt, _UU("CMD_MacDelete_Prompt"), CmdEvalNotEmpty, NULL},
  14815. };
  14816. // If virtual HUB is not selected, it's an error
  14817. if (ps->HubName == NULL)
  14818. {
  14819. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14820. return ERR_INVALID_PARAMETER;
  14821. }
  14822. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14823. if (o == NULL)
  14824. {
  14825. return ERR_INVALID_PARAMETER;
  14826. }
  14827. Zero(&t, sizeof(t));
  14828. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14829. t.Key = GetParamInt(o, "[id]");
  14830. // RPC call
  14831. ret = ScDeleteMacTable(ps->Rpc, &t);
  14832. if (ret != ERR_NO_ERROR)
  14833. {
  14834. // An error has occured
  14835. CmdPrintError(c, ret);
  14836. FreeParamValueList(o);
  14837. return ret;
  14838. }
  14839. FreeParamValueList(o);
  14840. return 0;
  14841. }
  14842. // Get the IP address table database
  14843. UINT PsIpTable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14844. {
  14845. LIST *o;
  14846. PS *ps = (PS *)param;
  14847. UINT ret = 0;
  14848. RPC_ENUM_IP_TABLE t;
  14849. UINT i;
  14850. // Parameter list that can be specified
  14851. PARAM args[] =
  14852. {
  14853. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  14854. {"[session_name]", NULL, NULL, NULL, NULL,}
  14855. };
  14856. // If virtual HUB is not selected, it's an error
  14857. if (ps->HubName == NULL)
  14858. {
  14859. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14860. return ERR_INVALID_PARAMETER;
  14861. }
  14862. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14863. if (o == NULL)
  14864. {
  14865. return ERR_INVALID_PARAMETER;
  14866. }
  14867. Zero(&t, sizeof(t));
  14868. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14869. // RPC call
  14870. ret = ScEnumIpTable(ps->Rpc, &t);
  14871. if (ret != ERR_NO_ERROR)
  14872. {
  14873. // An error has occured
  14874. CmdPrintError(c, ret);
  14875. FreeParamValueList(o);
  14876. return ret;
  14877. }
  14878. else
  14879. {
  14880. CT *ct = CtNew();
  14881. char *session_name = GetParamStr(o, "[session_name]");
  14882. if (IsEmptyStr(session_name))
  14883. {
  14884. session_name = NULL;
  14885. }
  14886. CtInsertColumn(ct, _UU("CMD_ID"), false);
  14887. CtInsertColumn(ct, _UU("SM_IP_COLUMN_1"), false);
  14888. CtInsertColumn(ct, _UU("SM_IP_COLUMN_2"), false);
  14889. CtInsertColumn(ct, _UU("SM_IP_COLUMN_3"), false);
  14890. CtInsertColumn(ct, _UU("SM_IP_COLUMN_4"), false);
  14891. CtInsertColumn(ct, _UU("SM_IP_COLUMN_5"), false);
  14892. for (i = 0;i < t.NumIpTable;i++)
  14893. {
  14894. char str[MAX_SIZE];
  14895. wchar_t tmp0[128];
  14896. wchar_t tmp1[MAX_SIZE];
  14897. wchar_t tmp2[MAX_SIZE];
  14898. wchar_t tmp3[MAX_SIZE];
  14899. wchar_t tmp4[MAX_SIZE];
  14900. wchar_t tmp5[MAX_SIZE];
  14901. RPC_ENUM_IP_TABLE_ITEM *e = &t.IpTables[i];
  14902. if (session_name == NULL || StrCmpi(e->SessionName, session_name) == 0)
  14903. {
  14904. UniToStru(tmp0, e->Key);
  14905. StrToUni(tmp1, sizeof(tmp1), e->SessionName);
  14906. if (e->DhcpAllocated == false)
  14907. {
  14908. IPToStr(str, sizeof(str), &e->IpV6);
  14909. StrToUni(tmp2, sizeof(tmp2), str);
  14910. }
  14911. else
  14912. {
  14913. IPToStr(str, sizeof(str), &e->IpV6);
  14914. UniFormat(tmp2, sizeof(tmp2), _UU("SM_MAC_IP_DHCP"), str);
  14915. }
  14916. GetDateTimeStr64Uni(tmp3, sizeof(tmp3), SystemToLocal64(e->CreatedTime));
  14917. GetDateTimeStr64Uni(tmp4, sizeof(tmp4), SystemToLocal64(e->UpdatedTime));
  14918. if (StrLen(e->RemoteHostname) == 0)
  14919. {
  14920. UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_MACIP_LOCAL"));
  14921. }
  14922. else
  14923. {
  14924. UniFormat(tmp5, sizeof(tmp5), _UU("SM_MACIP_SERVER"), e->RemoteHostname);
  14925. }
  14926. CtInsert(ct,
  14927. tmp0, tmp1, tmp2, tmp3, tmp4, tmp5);
  14928. }
  14929. }
  14930. CtFreeEx(ct, c, true);
  14931. }
  14932. FreeRpcEnumIpTable(&t);
  14933. FreeParamValueList(o);
  14934. return 0;
  14935. }
  14936. // Delete the IP address table entry
  14937. UINT PsIpDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14938. {
  14939. LIST *o;
  14940. PS *ps = (PS *)param;
  14941. UINT ret = 0;
  14942. RPC_DELETE_TABLE t;
  14943. // Parameter list that can be specified
  14944. PARAM args[] =
  14945. {
  14946. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  14947. {"[id]", CmdPrompt, _UU("CMD_MacDelete_Prompt"), CmdEvalNotEmpty, NULL},
  14948. };
  14949. // If virtual HUB is not selected, it's an error
  14950. if (ps->HubName == NULL)
  14951. {
  14952. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14953. return ERR_INVALID_PARAMETER;
  14954. }
  14955. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  14956. if (o == NULL)
  14957. {
  14958. return ERR_INVALID_PARAMETER;
  14959. }
  14960. Zero(&t, sizeof(t));
  14961. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14962. t.Key = GetParamInt(o, "[id]");
  14963. // RPC call
  14964. ret = ScDeleteIpTable(ps->Rpc, &t);
  14965. if (ret != ERR_NO_ERROR)
  14966. {
  14967. // An error has occured
  14968. CmdPrintError(c, ret);
  14969. FreeParamValueList(o);
  14970. return ret;
  14971. }
  14972. FreeParamValueList(o);
  14973. return 0;
  14974. }
  14975. // Enable the DHCP server function and the virtual NAT (SecureNAT function)
  14976. UINT PsSecureNatEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  14977. {
  14978. LIST *o;
  14979. PS *ps = (PS *)param;
  14980. UINT ret = 0;
  14981. RPC_HUB t;
  14982. // If virtual HUB is not selected, it's an error
  14983. if (ps->HubName == NULL)
  14984. {
  14985. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  14986. return ERR_INVALID_PARAMETER;
  14987. }
  14988. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  14989. if (o == NULL)
  14990. {
  14991. return ERR_INVALID_PARAMETER;
  14992. }
  14993. Zero(&t, sizeof(t));
  14994. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  14995. // RPC call
  14996. ret = ScEnableSecureNAT(ps->Rpc, &t);
  14997. if (ret != ERR_NO_ERROR)
  14998. {
  14999. // An error has occured
  15000. CmdPrintError(c, ret);
  15001. FreeParamValueList(o);
  15002. return ret;
  15003. }
  15004. FreeParamValueList(o);
  15005. return 0;
  15006. }
  15007. // Disable the DHCP server function and the virtual NAT (SecureNAT function)
  15008. UINT PsSecureNatDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15009. {
  15010. LIST *o;
  15011. PS *ps = (PS *)param;
  15012. UINT ret = 0;
  15013. RPC_HUB t;
  15014. // If virtual HUB is not selected, it's an error
  15015. if (ps->HubName == NULL)
  15016. {
  15017. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15018. return ERR_INVALID_PARAMETER;
  15019. }
  15020. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  15021. if (o == NULL)
  15022. {
  15023. return ERR_INVALID_PARAMETER;
  15024. }
  15025. Zero(&t, sizeof(t));
  15026. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15027. // RPC call
  15028. ret = ScDisableSecureNAT(ps->Rpc, &t);
  15029. if (ret != ERR_NO_ERROR)
  15030. {
  15031. // An error has occured
  15032. CmdPrintError(c, ret);
  15033. FreeParamValueList(o);
  15034. return ret;
  15035. }
  15036. FreeParamValueList(o);
  15037. return 0;
  15038. }
  15039. // Get the operating status of the DHCP server function and the virtual NAT (SecureNAT function)
  15040. UINT PsSecureNatStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15041. {
  15042. LIST *o;
  15043. PS *ps = (PS *)param;
  15044. UINT ret = 0;
  15045. RPC_NAT_STATUS t;
  15046. // If virtual HUB is not selected, it's an error
  15047. if (ps->HubName == NULL)
  15048. {
  15049. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15050. return ERR_INVALID_PARAMETER;
  15051. }
  15052. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  15053. if (o == NULL)
  15054. {
  15055. return ERR_INVALID_PARAMETER;
  15056. }
  15057. Zero(&t, sizeof(t));
  15058. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15059. // RPC call
  15060. ret = ScGetSecureNATStatus(ps->Rpc, &t);
  15061. if (ret != ERR_NO_ERROR)
  15062. {
  15063. // An error has occured
  15064. CmdPrintError(c, ret);
  15065. FreeParamValueList(o);
  15066. return ret;
  15067. }
  15068. else
  15069. {
  15070. wchar_t tmp[MAX_SIZE];
  15071. CT *ct = CtNewStandard();
  15072. StrToUni(tmp, sizeof(tmp), ps->HubName);
  15073. CtInsert(ct, _UU("SM_HUB_COLUMN_1"), tmp);
  15074. UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_SESSION"), t.NumTcpSessions);
  15075. CtInsert(ct, _UU("NM_STATUS_TCP"), tmp);
  15076. UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_SESSION"), t.NumUdpSessions);
  15077. CtInsert(ct, _UU("NM_STATUS_UDP"), tmp);
  15078. UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_SESSION"), t.NumIcmpSessions);
  15079. CtInsert(ct, _UU("NM_STATUS_ICMP"), tmp);
  15080. UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_SESSION"), t.NumDnsSessions);
  15081. CtInsert(ct, _UU("NM_STATUS_DNS"), tmp);
  15082. UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_CLIENT"), t.NumDhcpClients);
  15083. CtInsert(ct, _UU("NM_STATUS_DHCP"), tmp);
  15084. CtInsert(ct, _UU("SM_SNAT_IS_KERNEL"), t.IsKernelMode ? _UU("SEC_YES") : _UU("SEC_NO"));
  15085. CtInsert(ct, _UU("SM_SNAT_IS_RAW"), t.IsRawIpMode ? _UU("SEC_YES") : _UU("SEC_NO"));
  15086. CtFree(ct, c);
  15087. }
  15088. FreeRpcNatStatus(&t);
  15089. FreeParamValueList(o);
  15090. return 0;
  15091. }
  15092. // Get the network interface settings for a virtual host of SecureNAT function
  15093. UINT PsSecureNatHostGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15094. {
  15095. LIST *o;
  15096. PS *ps = (PS *)param;
  15097. UINT ret = 0;
  15098. VH_OPTION t;
  15099. // If virtual HUB is not selected, it's an error
  15100. if (ps->HubName == NULL)
  15101. {
  15102. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15103. return ERR_INVALID_PARAMETER;
  15104. }
  15105. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  15106. if (o == NULL)
  15107. {
  15108. return ERR_INVALID_PARAMETER;
  15109. }
  15110. Zero(&t, sizeof(t));
  15111. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15112. // RPC call
  15113. ret = ScGetSecureNATOption(ps->Rpc, &t);
  15114. if (ret != ERR_NO_ERROR)
  15115. {
  15116. // An error has occured
  15117. CmdPrintError(c, ret);
  15118. FreeParamValueList(o);
  15119. return ret;
  15120. }
  15121. else
  15122. {
  15123. wchar_t tmp[MAX_SIZE];
  15124. char str[MAX_SIZE];
  15125. CT *ct = CtNewStandard();
  15126. // Flags
  15127. // MAC Address
  15128. MacToStr(str, sizeof(str), t.MacAddress);
  15129. StrToUni(tmp, sizeof(tmp), str);
  15130. CtInsert(ct, _UU("CMD_SecureNatHostGet_Column_MAC"), tmp);
  15131. // IP address
  15132. IPToUniStr(tmp, sizeof(tmp), &t.Ip);
  15133. CtInsert(ct, _UU("CMD_SecureNatHostGet_Column_IP"), tmp);
  15134. // Subnet mask
  15135. IPToUniStr(tmp, sizeof(tmp), &t.Mask);
  15136. CtInsert(ct, _UU("CMD_SecureNatHostGet_Column_MASK"), tmp);
  15137. CtFree(ct, c);
  15138. }
  15139. FreeParamValueList(o);
  15140. return 0;
  15141. }
  15142. // Change the network interface settings for a virtual host of SecureNAT function
  15143. UINT PsSecureNatHostSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15144. {
  15145. LIST *o;
  15146. PS *ps = (PS *)param;
  15147. UINT ret = 0;
  15148. VH_OPTION t;
  15149. // Parameter list that can be specified
  15150. PARAM args[] =
  15151. {
  15152. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  15153. {"MAC", CmdPrompt, _UU("CMD_SecureNatHostSet_Prompt_MAC"), NULL, NULL},
  15154. {"IP", CmdPrompt, _UU("CMD_SecureNatHostSet_Prompt_IP"), CmdEvalIp, NULL},
  15155. {"MASK", CmdPrompt, _UU("CMD_SecureNatHostSet_Prompt_MASK"), CmdEvalIp, NULL},
  15156. };
  15157. // If virtual HUB is not selected, it's an error
  15158. if (ps->HubName == NULL)
  15159. {
  15160. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15161. return ERR_INVALID_PARAMETER;
  15162. }
  15163. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  15164. if (o == NULL)
  15165. {
  15166. return ERR_INVALID_PARAMETER;
  15167. }
  15168. Zero(&t, sizeof(t));
  15169. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15170. // RPC call
  15171. ret = ScGetSecureNATOption(ps->Rpc, &t);
  15172. if (ret != ERR_NO_ERROR)
  15173. {
  15174. // An error has occured
  15175. CmdPrintError(c, ret);
  15176. FreeParamValueList(o);
  15177. return ret;
  15178. }
  15179. else
  15180. {
  15181. char *mac, *ip, *mask;
  15182. bool ok = true;
  15183. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15184. mac = GetParamStr(o, "MAC");
  15185. ip = GetParamStr(o, "IP");
  15186. mask = GetParamStr(o, "MASK");
  15187. if (IsEmptyStr(mac) == false)
  15188. {
  15189. BUF *b = StrToBin(mac);
  15190. if (b == NULL || b->Size != 6)
  15191. {
  15192. ok = false;
  15193. }
  15194. else
  15195. {
  15196. Copy(t.MacAddress, b->Buf, 6);
  15197. }
  15198. FreeBuf(b);
  15199. }
  15200. if (IsEmptyStr(ip) == false)
  15201. {
  15202. if (IsIpStr4(ip) == false)
  15203. {
  15204. ok = false;
  15205. }
  15206. else
  15207. {
  15208. UINT u = StrToIP32(ip);
  15209. if (u == 0 || u == 0xffffffff)
  15210. {
  15211. ok = false;
  15212. }
  15213. else
  15214. {
  15215. UINTToIP(&t.Ip, u);
  15216. }
  15217. }
  15218. }
  15219. if (IsEmptyStr(mask) == false)
  15220. {
  15221. if (IsIpStr4(mask) == false)
  15222. {
  15223. ok = false;
  15224. }
  15225. else
  15226. {
  15227. StrToIP(&t.Mask, mask);
  15228. }
  15229. }
  15230. if (ok == false)
  15231. {
  15232. // Parameter is invalid
  15233. ret = ERR_INVALID_PARAMETER;
  15234. CmdPrintError(c, ret);
  15235. FreeParamValueList(o);
  15236. return ret;
  15237. }
  15238. else
  15239. {
  15240. ret = ScSetSecureNATOption(ps->Rpc, &t);
  15241. if (ret != ERR_NO_ERROR)
  15242. {
  15243. // An error has occured
  15244. CmdPrintError(c, ret);
  15245. FreeParamValueList(o);
  15246. return ret;
  15247. }
  15248. }
  15249. }
  15250. FreeParamValueList(o);
  15251. return 0;
  15252. }
  15253. // Get the settings for the virtual NAT function of the SecureNAT function
  15254. UINT PsNatGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15255. {
  15256. LIST *o;
  15257. PS *ps = (PS *)param;
  15258. UINT ret = 0;
  15259. VH_OPTION t;
  15260. // If virtual HUB is not selected, it's an error
  15261. if (ps->HubName == NULL)
  15262. {
  15263. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15264. return ERR_INVALID_PARAMETER;
  15265. }
  15266. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  15267. if (o == NULL)
  15268. {
  15269. return ERR_INVALID_PARAMETER;
  15270. }
  15271. Zero(&t, sizeof(t));
  15272. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15273. // RPC call
  15274. ret = ScGetSecureNATOption(ps->Rpc, &t);
  15275. if (ret != ERR_NO_ERROR)
  15276. {
  15277. // An error has occured
  15278. CmdPrintError(c, ret);
  15279. FreeParamValueList(o);
  15280. return ret;
  15281. }
  15282. else
  15283. {
  15284. wchar_t tmp[MAX_SIZE];
  15285. CT *ct = CtNewStandard();
  15286. // Use the virtual NAT function
  15287. CtInsert(ct, _UU("CMD_NatGet_Column_USE"), t.UseNat ? _UU("SEC_YES") : _UU("SEC_NO"));
  15288. // MTU value
  15289. UniToStru(tmp, t.Mtu);
  15290. CtInsert(ct, _UU("CMD_NetGet_Column_MTU"), tmp);
  15291. // TCP session timeout (in seconds)
  15292. UniToStru(tmp, t.NatTcpTimeout);
  15293. CtInsert(ct, _UU("CMD_NatGet_Column_TCP"), tmp);
  15294. // UDP session timeout (in seconds)
  15295. UniToStru(tmp, t.NatUdpTimeout);
  15296. CtInsert(ct, _UU("CMD_NatGet_Column_UDP"), tmp);
  15297. // To save the log
  15298. CtInsert(ct, _UU("CMD_SecureNatHostGet_Column_LOG"), t.SaveLog ? _UU("SEC_YES") : _UU("SEC_NO"));
  15299. CtFree(ct, c);
  15300. }
  15301. FreeParamValueList(o);
  15302. return 0;
  15303. }
  15304. // Enable the virtual NAT function of the SecureNAT function
  15305. UINT PsNatEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15306. {
  15307. LIST *o;
  15308. PS *ps = (PS *)param;
  15309. UINT ret = 0;
  15310. VH_OPTION t;
  15311. // If virtual HUB is not selected, it's an error
  15312. if (ps->HubName == NULL)
  15313. {
  15314. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15315. return ERR_INVALID_PARAMETER;
  15316. }
  15317. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  15318. if (o == NULL)
  15319. {
  15320. return ERR_INVALID_PARAMETER;
  15321. }
  15322. Zero(&t, sizeof(t));
  15323. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15324. // RPC call
  15325. ret = ScGetSecureNATOption(ps->Rpc, &t);
  15326. if (ret != ERR_NO_ERROR)
  15327. {
  15328. // An error has occured
  15329. CmdPrintError(c, ret);
  15330. FreeParamValueList(o);
  15331. return ret;
  15332. }
  15333. else
  15334. {
  15335. bool ok = true;
  15336. t.UseNat = true;
  15337. if (ok == false)
  15338. {
  15339. // Parameter is invalid
  15340. ret = ERR_INVALID_PARAMETER;
  15341. CmdPrintError(c, ret);
  15342. FreeParamValueList(o);
  15343. return ret;
  15344. }
  15345. else
  15346. {
  15347. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15348. ret = ScSetSecureNATOption(ps->Rpc, &t);
  15349. if (ret != ERR_NO_ERROR)
  15350. {
  15351. // An error has occured
  15352. CmdPrintError(c, ret);
  15353. FreeParamValueList(o);
  15354. return ret;
  15355. }
  15356. }
  15357. }
  15358. FreeParamValueList(o);
  15359. return 0;
  15360. }
  15361. // Disable the virtual NAT function of the SecureNAT function
  15362. UINT PsNatDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15363. {
  15364. LIST *o;
  15365. PS *ps = (PS *)param;
  15366. UINT ret = 0;
  15367. VH_OPTION t;
  15368. // If virtual HUB is not selected, it's an error
  15369. if (ps->HubName == NULL)
  15370. {
  15371. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15372. return ERR_INVALID_PARAMETER;
  15373. }
  15374. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  15375. if (o == NULL)
  15376. {
  15377. return ERR_INVALID_PARAMETER;
  15378. }
  15379. Zero(&t, sizeof(t));
  15380. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15381. // RPC call
  15382. ret = ScGetSecureNATOption(ps->Rpc, &t);
  15383. if (ret != ERR_NO_ERROR)
  15384. {
  15385. // An error has occured
  15386. CmdPrintError(c, ret);
  15387. FreeParamValueList(o);
  15388. return ret;
  15389. }
  15390. else
  15391. {
  15392. bool ok = true;
  15393. t.UseNat = false;
  15394. if (ok == false)
  15395. {
  15396. // Parameter is invalid
  15397. ret = ERR_INVALID_PARAMETER;
  15398. CmdPrintError(c, ret);
  15399. FreeParamValueList(o);
  15400. return ret;
  15401. }
  15402. else
  15403. {
  15404. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15405. ret = ScSetSecureNATOption(ps->Rpc, &t);
  15406. if (ret != ERR_NO_ERROR)
  15407. {
  15408. // An error has occured
  15409. CmdPrintError(c, ret);
  15410. FreeParamValueList(o);
  15411. return ret;
  15412. }
  15413. }
  15414. }
  15415. FreeParamValueList(o);
  15416. return 0;
  15417. }
  15418. // Change the settings for the virtual NAT function of the SecureNAT function
  15419. UINT PsNatSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15420. {
  15421. LIST *o;
  15422. PS *ps = (PS *)param;
  15423. UINT ret = 0;
  15424. VH_OPTION t;
  15425. // Parameter list that can be specified
  15426. CMD_EVAL_MIN_MAX mtu_mm =
  15427. {
  15428. "CMD_NatSet_Eval_MTU", TCP_HEADER_SIZE + IP_HEADER_SIZE + MAC_HEADER_SIZE + 8, MAX_L3_DATA_SIZE,
  15429. };
  15430. CMD_EVAL_MIN_MAX tcp_mm =
  15431. {
  15432. "CMD_NatSet_Eval_TCP", NAT_TCP_MIN_TIMEOUT / 1000, NAT_TCP_MAX_TIMEOUT / 1000,
  15433. };
  15434. CMD_EVAL_MIN_MAX udp_mm =
  15435. {
  15436. "CMD_NatSet_Eval_UDP", NAT_UDP_MIN_TIMEOUT / 1000, NAT_UDP_MAX_TIMEOUT / 1000,
  15437. };
  15438. PARAM args[] =
  15439. {
  15440. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  15441. {"MTU", CmdPrompt, _UU("CMD_NatSet_Prompt_MTU"), CmdEvalMinMax, &mtu_mm},
  15442. {"TCPTIMEOUT", CmdPrompt, _UU("CMD_NatSet_Prompt_TCPTIMEOUT"), CmdEvalMinMax, &tcp_mm},
  15443. {"UDPTIMEOUT", CmdPrompt, _UU("CMD_NatSet_Prompt_UDPTIMEOUT"), CmdEvalMinMax, &udp_mm},
  15444. {"LOG", CmdPrompt, _UU("CMD_NatSet_Prompt_LOG"), CmdEvalNotEmpty, NULL},
  15445. };
  15446. // If virtual HUB is not selected, it's an error
  15447. if (ps->HubName == NULL)
  15448. {
  15449. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15450. return ERR_INVALID_PARAMETER;
  15451. }
  15452. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  15453. if (o == NULL)
  15454. {
  15455. return ERR_INVALID_PARAMETER;
  15456. }
  15457. Zero(&t, sizeof(t));
  15458. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15459. // RPC call
  15460. ret = ScGetSecureNATOption(ps->Rpc, &t);
  15461. if (ret != ERR_NO_ERROR)
  15462. {
  15463. // An error has occured
  15464. CmdPrintError(c, ret);
  15465. FreeParamValueList(o);
  15466. return ret;
  15467. }
  15468. else
  15469. {
  15470. bool ok = true;
  15471. t.Mtu = GetParamInt(o, "MTU");
  15472. t.NatTcpTimeout = GetParamInt(o, "TCPTIMEOUT");
  15473. t.NatUdpTimeout = GetParamInt(o, "UDPTIMEOUT");
  15474. t.SaveLog = GetParamYes(o, "LOG");
  15475. if (ok == false)
  15476. {
  15477. // Parameter is invalid
  15478. ret = ERR_INVALID_PARAMETER;
  15479. CmdPrintError(c, ret);
  15480. FreeParamValueList(o);
  15481. return ret;
  15482. }
  15483. else
  15484. {
  15485. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15486. ret = ScSetSecureNATOption(ps->Rpc, &t);
  15487. if (ret != ERR_NO_ERROR)
  15488. {
  15489. // An error has occured
  15490. CmdPrintError(c, ret);
  15491. FreeParamValueList(o);
  15492. return ret;
  15493. }
  15494. }
  15495. }
  15496. FreeParamValueList(o);
  15497. return 0;
  15498. }
  15499. // Get the session table of the virtual NAT function of the SecureNAT function
  15500. UINT PsNatTable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15501. {
  15502. LIST *o;
  15503. PS *ps = (PS *)param;
  15504. UINT ret = 0;
  15505. RPC_ENUM_NAT t;
  15506. // If virtual HUB is not selected, it's an error
  15507. if (ps->HubName == NULL)
  15508. {
  15509. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15510. return ERR_INVALID_PARAMETER;
  15511. }
  15512. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  15513. if (o == NULL)
  15514. {
  15515. return ERR_INVALID_PARAMETER;
  15516. }
  15517. Zero(&t, sizeof(t));
  15518. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15519. // RPC call
  15520. ret = ScEnumNAT(ps->Rpc, &t);
  15521. if (ret != ERR_NO_ERROR)
  15522. {
  15523. // An error has occured
  15524. CmdPrintError(c, ret);
  15525. FreeParamValueList(o);
  15526. return ret;
  15527. }
  15528. else
  15529. {
  15530. CT *ct = CtNew();
  15531. UINT i;
  15532. CtInsertColumn(ct, _UU("NM_NAT_ID"), false);
  15533. CtInsertColumn(ct, _UU("NM_NAT_PROTOCOL"), false);
  15534. CtInsertColumn(ct, _UU("NM_NAT_SRC_HOST"), false);
  15535. CtInsertColumn(ct, _UU("NM_NAT_SRC_PORT"), false);
  15536. CtInsertColumn(ct, _UU("NM_NAT_DST_HOST"), false);
  15537. CtInsertColumn(ct, _UU("NM_NAT_DST_PORT"), false);
  15538. CtInsertColumn(ct, _UU("NM_NAT_CREATED"), false);
  15539. CtInsertColumn(ct, _UU("NM_NAT_LAST_COMM"), false);
  15540. CtInsertColumn(ct, _UU("NM_NAT_SIZE"), false);
  15541. CtInsertColumn(ct, _UU("NM_NAT_TCP_STATUS"), false);
  15542. for (i = 0;i < t.NumItem;i++)
  15543. {
  15544. RPC_ENUM_NAT_ITEM *e = &t.Items[i];
  15545. wchar_t tmp0[MAX_SIZE];
  15546. wchar_t *tmp1 = L"";
  15547. wchar_t tmp2[MAX_SIZE];
  15548. wchar_t tmp3[MAX_SIZE];
  15549. wchar_t tmp4[MAX_SIZE];
  15550. wchar_t tmp5[MAX_SIZE];
  15551. wchar_t tmp6[MAX_SIZE];
  15552. wchar_t tmp7[MAX_SIZE];
  15553. wchar_t tmp8[MAX_SIZE];
  15554. wchar_t *tmp9 = L"";
  15555. char v1[128], v2[128];
  15556. // ID
  15557. UniToStru(tmp0, e->Id);
  15558. // Protocol
  15559. switch (e->Protocol)
  15560. {
  15561. case NAT_TCP:
  15562. tmp1 = _UU("NM_NAT_PROTO_TCP");
  15563. break;
  15564. case NAT_UDP:
  15565. tmp1 = _UU("NM_NAT_PROTO_UDP");
  15566. break;
  15567. case NAT_DNS:
  15568. tmp1 = _UU("NM_NAT_PROTO_DNS");
  15569. break;
  15570. case NAT_ICMP:
  15571. tmp1 = _UU("NM_NAT_PROTO_ICMP");
  15572. break;
  15573. }
  15574. // Source host
  15575. StrToUni(tmp2, sizeof(tmp2), e->SrcHost);
  15576. // Source port
  15577. UniToStru(tmp3, e->SrcPort);
  15578. // Destination host
  15579. StrToUni(tmp4, sizeof(tmp4), e->DestHost);
  15580. // Destination port
  15581. UniToStru(tmp5, e->DestPort);
  15582. // Creation date and time of the session
  15583. GetDateTimeStrEx64(tmp6, sizeof(tmp6), SystemToLocal64(e->CreatedTime), NULL);
  15584. // Last communication date and time
  15585. GetDateTimeStrEx64(tmp7, sizeof(tmp7), SystemToLocal64(e->LastCommTime), NULL);
  15586. // Communication amount
  15587. ToStr3(v1, sizeof(v1), e->RecvSize);
  15588. ToStr3(v2, sizeof(v2), e->SendSize);
  15589. UniFormat(tmp8, sizeof(tmp8), L"%S / %S", v1, v2);
  15590. // TCP state
  15591. if (e->Protocol == NAT_TCP)
  15592. {
  15593. switch (e->TcpStatus)
  15594. {
  15595. case NAT_TCP_CONNECTING:
  15596. tmp9 = _UU("NAT_TCP_CONNECTING");
  15597. break;
  15598. case NAT_TCP_SEND_RESET:
  15599. tmp9 = _UU("NAT_TCP_SEND_RESET");
  15600. break;
  15601. case NAT_TCP_CONNECTED:
  15602. tmp9 = _UU("NAT_TCP_CONNECTED");
  15603. break;
  15604. case NAT_TCP_ESTABLISHED:
  15605. tmp9 = _UU("NAT_TCP_ESTABLISHED");
  15606. break;
  15607. case NAT_TCP_WAIT_DISCONNECT:
  15608. tmp9 = _UU("NAT_TCP_WAIT_DISCONNECT");
  15609. break;
  15610. }
  15611. }
  15612. CtInsert(ct,
  15613. tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9);
  15614. }
  15615. CtFreeEx(ct, c, true);
  15616. }
  15617. FreeRpcEnumNat(&t);
  15618. FreeParamValueList(o);
  15619. return 0;
  15620. }
  15621. // Get the settings for a virtual DHCP server function of the SecureNAT function
  15622. UINT PsDhcpGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15623. {
  15624. LIST *o;
  15625. PS *ps = (PS *)param;
  15626. UINT ret = 0;
  15627. VH_OPTION t;
  15628. // If virtual HUB is not selected, it's an error
  15629. if (ps->HubName == NULL)
  15630. {
  15631. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15632. return ERR_INVALID_PARAMETER;
  15633. }
  15634. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  15635. if (o == NULL)
  15636. {
  15637. return ERR_INVALID_PARAMETER;
  15638. }
  15639. Zero(&t, sizeof(t));
  15640. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15641. // RPC call
  15642. ret = ScGetSecureNATOption(ps->Rpc, &t);
  15643. if (ret != ERR_NO_ERROR)
  15644. {
  15645. // An error has occured
  15646. CmdPrintError(c, ret);
  15647. FreeParamValueList(o);
  15648. return ret;
  15649. }
  15650. else
  15651. {
  15652. wchar_t tmp[MAX_SIZE];
  15653. CT *ct = CtNewStandard();
  15654. // To use the virtual DHCP function
  15655. CtInsert(ct, _UU("CMD_DhcpGet_Column_USE"), t.UseDhcp ? _UU("SEC_YES") : _UU("SEC_NO"));
  15656. // Start address of the distributing address zone
  15657. IPToUniStr(tmp, sizeof(tmp), &t.DhcpLeaseIPStart);
  15658. CtInsert(ct, _UU("CMD_DhcpGet_Column_IP1"), tmp);
  15659. // End address of the distributing address zone
  15660. IPToUniStr(tmp, sizeof(tmp), &t.DhcpLeaseIPEnd);
  15661. CtInsert(ct, _UU("CMD_DhcpGet_Column_IP2"), tmp);
  15662. // Subnet mask
  15663. IPToUniStr(tmp, sizeof(tmp), &t.DhcpSubnetMask);
  15664. CtInsert(ct, _UU("CMD_DhcpGet_Column_MASK"), tmp);
  15665. // Lease time (in seconds)
  15666. UniToStru(tmp, t.DhcpExpireTimeSpan);
  15667. CtInsert(ct, _UU("CMD_DhcpGet_Column_LEASE"), tmp);
  15668. // Default gateway address
  15669. UniStrCpy(tmp, sizeof(tmp), _UU("SEC_NONE"));
  15670. if (IPToUINT(&t.DhcpGatewayAddress) != 0)
  15671. {
  15672. IPToUniStr(tmp, sizeof(tmp), &t.DhcpGatewayAddress);
  15673. }
  15674. CtInsert(ct, _UU("CMD_DhcpGet_Column_GW"), tmp);
  15675. // DNS server address 1
  15676. UniStrCpy(tmp, sizeof(tmp), _UU("SEC_NONE"));
  15677. if (IPToUINT(&t.DhcpDnsServerAddress) != 0)
  15678. {
  15679. IPToUniStr(tmp, sizeof(tmp), &t.DhcpDnsServerAddress);
  15680. }
  15681. CtInsert(ct, _UU("CMD_DhcpGet_Column_DNS"), tmp);
  15682. // DNS server address 2
  15683. UniStrCpy(tmp, sizeof(tmp), _UU("SEC_NONE"));
  15684. if (IPToUINT(&t.DhcpDnsServerAddress2) != 0)
  15685. {
  15686. IPToUniStr(tmp, sizeof(tmp), &t.DhcpDnsServerAddress2);
  15687. }
  15688. CtInsert(ct, _UU("CMD_DhcpGet_Column_DNS2"), tmp);
  15689. // Domain name
  15690. StrToUni(tmp, sizeof(tmp), t.DhcpDomainName);
  15691. CtInsert(ct, _UU("CMD_DhcpGet_Column_DOMAIN"), tmp);
  15692. // To save the log
  15693. CtInsert(ct, _UU("CMD_SecureNatHostGet_Column_LOG"), t.SaveLog ? _UU("SEC_YES") : _UU("SEC_NO"));
  15694. // Push routing table
  15695. if (t.ApplyDhcpPushRoutes)
  15696. {
  15697. StrToUni(tmp, sizeof(tmp), t.DhcpPushRoutes);
  15698. CtInsert(ct, _UU("CMD_DhcpGet_Column_PUSHROUTE"), tmp);
  15699. }
  15700. CtFree(ct, c);
  15701. }
  15702. FreeParamValueList(o);
  15703. return 0;
  15704. }
  15705. // Enable the Virtual DHCP server function of SecureNAT function
  15706. UINT PsDhcpEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15707. {
  15708. LIST *o;
  15709. PS *ps = (PS *)param;
  15710. UINT ret = 0;
  15711. VH_OPTION t;
  15712. // If virtual HUB is not selected, it's an error
  15713. if (ps->HubName == NULL)
  15714. {
  15715. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15716. return ERR_INVALID_PARAMETER;
  15717. }
  15718. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  15719. if (o == NULL)
  15720. {
  15721. return ERR_INVALID_PARAMETER;
  15722. }
  15723. Zero(&t, sizeof(t));
  15724. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15725. // RPC call
  15726. ret = ScGetSecureNATOption(ps->Rpc, &t);
  15727. if (ret != ERR_NO_ERROR)
  15728. {
  15729. // An error has occured
  15730. CmdPrintError(c, ret);
  15731. FreeParamValueList(o);
  15732. return ret;
  15733. }
  15734. else
  15735. {
  15736. bool ok = true;
  15737. t.UseDhcp = true;
  15738. if (ok == false)
  15739. {
  15740. // Parameter is invalid
  15741. ret = ERR_INVALID_PARAMETER;
  15742. CmdPrintError(c, ret);
  15743. FreeParamValueList(o);
  15744. return ret;
  15745. }
  15746. else
  15747. {
  15748. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15749. ret = ScSetSecureNATOption(ps->Rpc, &t);
  15750. if (ret != ERR_NO_ERROR)
  15751. {
  15752. // An error has occured
  15753. CmdPrintError(c, ret);
  15754. FreeParamValueList(o);
  15755. return ret;
  15756. }
  15757. }
  15758. }
  15759. FreeParamValueList(o);
  15760. return 0;
  15761. }
  15762. // Disable the virtual DHCP server function of SecureNAT function
  15763. UINT PsDhcpDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15764. {
  15765. LIST *o;
  15766. PS *ps = (PS *)param;
  15767. UINT ret = 0;
  15768. VH_OPTION t;
  15769. // If virtual HUB is not selected, it's an error
  15770. if (ps->HubName == NULL)
  15771. {
  15772. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15773. return ERR_INVALID_PARAMETER;
  15774. }
  15775. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  15776. if (o == NULL)
  15777. {
  15778. return ERR_INVALID_PARAMETER;
  15779. }
  15780. Zero(&t, sizeof(t));
  15781. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15782. // RPC call
  15783. ret = ScGetSecureNATOption(ps->Rpc, &t);
  15784. if (ret != ERR_NO_ERROR)
  15785. {
  15786. // An error has occured
  15787. CmdPrintError(c, ret);
  15788. FreeParamValueList(o);
  15789. return ret;
  15790. }
  15791. else
  15792. {
  15793. bool ok = true;
  15794. t.UseDhcp = false;
  15795. if (ok == false)
  15796. {
  15797. // Parameter is invalid
  15798. ret = ERR_INVALID_PARAMETER;
  15799. CmdPrintError(c, ret);
  15800. FreeParamValueList(o);
  15801. return ret;
  15802. }
  15803. else
  15804. {
  15805. ret = ScSetSecureNATOption(ps->Rpc, &t);
  15806. if (ret != ERR_NO_ERROR)
  15807. {
  15808. // An error has occured
  15809. CmdPrintError(c, ret);
  15810. FreeParamValueList(o);
  15811. return ret;
  15812. }
  15813. }
  15814. }
  15815. FreeParamValueList(o);
  15816. return 0;
  15817. }
  15818. // Change the settings for a virtual DHCP server function of the SecureNAT function
  15819. UINT PsDhcpSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15820. {
  15821. LIST *o;
  15822. PS *ps = (PS *)param;
  15823. UINT ret = 0;
  15824. VH_OPTION t;
  15825. // Parameter list that can be specified
  15826. CMD_EVAL_MIN_MAX mm =
  15827. {
  15828. "CMD_NatSet_Eval_UDP", NAT_UDP_MIN_TIMEOUT / 1000, NAT_UDP_MAX_TIMEOUT / 1000,
  15829. };
  15830. PARAM args[] =
  15831. {
  15832. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  15833. {"START", CmdPrompt, _UU("CMD_DhcpSet_Prompt_START"), CmdEvalIp, NULL},
  15834. {"END", CmdPrompt, _UU("CMD_DhcpSet_Prompt_END"), CmdEvalIp, NULL},
  15835. {"MASK", CmdPrompt, _UU("CMD_DhcpSet_Prompt_MASK"), CmdEvalIp, NULL},
  15836. {"EXPIRE", CmdPrompt, _UU("CMD_DhcpSet_Prompt_EXPIRE"), CmdEvalMinMax, &mm},
  15837. {"GW", CmdPrompt, _UU("CMD_DhcpSet_Prompt_GW"), CmdEvalIp, NULL},
  15838. {"DNS", CmdPrompt, _UU("CMD_DhcpSet_Prompt_DNS"), CmdEvalIp, NULL},
  15839. {"DNS2", CmdPrompt, _UU("CMD_DhcpSet_Prompt_DNS2"), CmdEvalIp, NULL},
  15840. {"DOMAIN", CmdPrompt, _UU("CMD_DhcpSet_Prompt_DOMAIN"), NULL, NULL},
  15841. {"LOG", CmdPrompt, _UU("CMD_NatSet_Prompt_LOG"), CmdEvalNotEmpty, NULL},
  15842. {"PUSHROUTE", NULL, _UU("CMD_DhcpSet_PUSHROUTE"), NULL, NULL},
  15843. };
  15844. // If virtual HUB is not selected, it's an error
  15845. if (ps->HubName == NULL)
  15846. {
  15847. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15848. return ERR_INVALID_PARAMETER;
  15849. }
  15850. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  15851. if (o == NULL)
  15852. {
  15853. return ERR_INVALID_PARAMETER;
  15854. }
  15855. Zero(&t, sizeof(t));
  15856. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15857. // RPC call
  15858. ret = ScGetSecureNATOption(ps->Rpc, &t);
  15859. if (ret != ERR_NO_ERROR)
  15860. {
  15861. // An error has occured
  15862. CmdPrintError(c, ret);
  15863. FreeParamValueList(o);
  15864. return ret;
  15865. }
  15866. else
  15867. {
  15868. bool ok = true;
  15869. StrToIP(&t.DhcpLeaseIPStart, GetParamStr(o, "START"));
  15870. StrToIP(&t.DhcpLeaseIPEnd, GetParamStr(o, "END"));
  15871. StrToIP(&t.DhcpSubnetMask, GetParamStr(o, "MASK"));
  15872. t.DhcpExpireTimeSpan = GetParamInt(o, "EXPIRE");
  15873. StrToIP(&t.DhcpGatewayAddress, GetParamStr(o, "GW"));
  15874. StrToIP(&t.DhcpDnsServerAddress, GetParamStr(o, "DNS"));
  15875. StrToIP(&t.DhcpDnsServerAddress2, GetParamStr(o, "DNS2"));
  15876. StrCpy(t.DhcpDomainName, sizeof(t.DhcpDomainName), GetParamStr(o, "DOMAIN"));
  15877. t.SaveLog = GetParamYes(o, "LOG");
  15878. StrCpy(t.DhcpPushRoutes, sizeof(t.DhcpPushRoutes), GetParamStr(o, "PUSHROUTE"));
  15879. t.ApplyDhcpPushRoutes = true;
  15880. if (ok == false)
  15881. {
  15882. // Parameter is invalid
  15883. ret = ERR_INVALID_PARAMETER;
  15884. CmdPrintError(c, ret);
  15885. FreeParamValueList(o);
  15886. return ret;
  15887. }
  15888. else
  15889. {
  15890. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15891. ret = ScSetSecureNATOption(ps->Rpc, &t);
  15892. if (ret != ERR_NO_ERROR)
  15893. {
  15894. // An error has occured
  15895. CmdPrintError(c, ret);
  15896. FreeParamValueList(o);
  15897. return ret;
  15898. }
  15899. if (IsEmptyStr(GetParamStr(o, "PUSHROUTE")) == false)
  15900. {
  15901. if (GetCapsBool(ps->CapsList, "b_suppport_push_route") == false &&
  15902. GetCapsBool(ps->CapsList, "b_suppport_push_route_config"))
  15903. {
  15904. CmdPrintError(c, ERR_NOT_SUPPORTED_FUNCTION_ON_OPENSOURCE);
  15905. }
  15906. }
  15907. }
  15908. }
  15909. FreeParamValueList(o);
  15910. return 0;
  15911. }
  15912. // Get the lease table of virtual DHCP server function of the SecureNAT function
  15913. UINT PsDhcpTable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15914. {
  15915. LIST *o;
  15916. PS *ps = (PS *)param;
  15917. UINT ret = 0;
  15918. RPC_ENUM_DHCP t;
  15919. // If virtual HUB is not selected, it's an error
  15920. if (ps->HubName == NULL)
  15921. {
  15922. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15923. return ERR_INVALID_PARAMETER;
  15924. }
  15925. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  15926. if (o == NULL)
  15927. {
  15928. return ERR_INVALID_PARAMETER;
  15929. }
  15930. Zero(&t, sizeof(t));
  15931. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  15932. // RPC call
  15933. ret = ScEnumDHCP(ps->Rpc, &t);
  15934. if (ret != ERR_NO_ERROR)
  15935. {
  15936. // An error has occured
  15937. CmdPrintError(c, ret);
  15938. FreeParamValueList(o);
  15939. return ret;
  15940. }
  15941. else
  15942. {
  15943. CT *ct = CtNew();
  15944. UINT i;
  15945. CtInsertColumn(ct, _UU("DHCP_DHCP_ID"), false);
  15946. CtInsertColumn(ct, _UU("DHCP_LEASED_TIME"), false);
  15947. CtInsertColumn(ct, _UU("DHCP_EXPIRE_TIME"), false);
  15948. CtInsertColumn(ct, _UU("DHCP_MAC_ADDRESS"), false);
  15949. CtInsertColumn(ct, _UU("DHCP_IP_ADDRESS"), false);
  15950. CtInsertColumn(ct, _UU("DHCP_HOSTNAME"), false);
  15951. for (i = 0;i < t.NumItem;i++)
  15952. {
  15953. RPC_ENUM_DHCP_ITEM *e = &t.Items[i];
  15954. wchar_t tmp0[MAX_SIZE];
  15955. wchar_t tmp1[MAX_SIZE];
  15956. wchar_t tmp2[MAX_SIZE];
  15957. wchar_t tmp3[MAX_SIZE];
  15958. wchar_t tmp4[MAX_SIZE];
  15959. wchar_t tmp5[MAX_SIZE];
  15960. char str[MAX_SIZE];
  15961. // ID
  15962. UniToStru(tmp0, e->Id);
  15963. // Time
  15964. GetDateTimeStrEx64(tmp1, sizeof(tmp1), SystemToLocal64(e->LeasedTime), NULL);
  15965. GetDateTimeStrEx64(tmp2, sizeof(tmp2), SystemToLocal64(e->ExpireTime), NULL);
  15966. MacToStr(str, sizeof(str), e->MacAddress);
  15967. StrToUni(tmp3, sizeof(tmp3), str);
  15968. IPToStr32(str, sizeof(str), e->IpAddress);
  15969. StrToUni(tmp4, sizeof(tmp4), str);
  15970. StrToUni(tmp5, sizeof(tmp5), e->Hostname);
  15971. CtInsert(ct,
  15972. tmp0, tmp1, tmp2, tmp3, tmp4, tmp5);
  15973. }
  15974. CtFreeEx(ct, c, true);
  15975. }
  15976. FreeRpcEnumDhcp(&t);
  15977. FreeParamValueList(o);
  15978. return 0;
  15979. }
  15980. // Get the list of Virtual HUB management options
  15981. UINT PsAdminOptionList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  15982. {
  15983. LIST *o;
  15984. PS *ps = (PS *)param;
  15985. UINT ret = 0;
  15986. RPC_ADMIN_OPTION t;
  15987. // If virtual HUB is not selected, it's an error
  15988. if (ps->HubName == NULL)
  15989. {
  15990. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  15991. return ERR_INVALID_PARAMETER;
  15992. }
  15993. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  15994. if (o == NULL)
  15995. {
  15996. return ERR_INVALID_PARAMETER;
  15997. }
  15998. Zero(&t, sizeof(t));
  15999. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16000. // RPC call
  16001. ret = ScGetHubAdminOptions(ps->Rpc, &t);
  16002. if (ret != ERR_NO_ERROR)
  16003. {
  16004. // An error has occured
  16005. CmdPrintError(c, ret);
  16006. FreeParamValueList(o);
  16007. return ret;
  16008. }
  16009. else
  16010. {
  16011. CT *ct = CtNewStandardEx();
  16012. UINT i;
  16013. for (i = 0;i < t.NumItem;i++)
  16014. {
  16015. ADMIN_OPTION *e = &t.Items[i];
  16016. wchar_t tmp1[MAX_SIZE];
  16017. wchar_t tmp2[MAX_SIZE];
  16018. StrToUni(tmp1, sizeof(tmp1), e->Name);
  16019. UniToStru(tmp2, e->Value);
  16020. CtInsert(ct, tmp1, tmp2, GetHubAdminOptionHelpString(e->Name));
  16021. }
  16022. CtFreeEx(ct, c, true);
  16023. }
  16024. FreeRpcAdminOption(&t);
  16025. FreeParamValueList(o);
  16026. return 0;
  16027. }
  16028. // Set the value of a Virtual HUB management option
  16029. UINT PsAdminOptionSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16030. {
  16031. LIST *o;
  16032. PS *ps = (PS *)param;
  16033. UINT ret = 0;
  16034. RPC_ADMIN_OPTION t;
  16035. // Parameter list that can be specified
  16036. PARAM args[] =
  16037. {
  16038. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  16039. {"[name]", CmdPrompt, _UU("CMD_AdminOptionSet_Prompt_name"), CmdEvalNotEmpty, NULL},
  16040. {"VALUE", CmdPrompt, _UU("CMD_AdminOptionSet_Prompt_VALUE"), CmdEvalNotEmpty, NULL},
  16041. };
  16042. // If virtual HUB is not selected, it's an error
  16043. if (ps->HubName == NULL)
  16044. {
  16045. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  16046. return ERR_INVALID_PARAMETER;
  16047. }
  16048. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  16049. if (o == NULL)
  16050. {
  16051. return ERR_INVALID_PARAMETER;
  16052. }
  16053. Zero(&t, sizeof(t));
  16054. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16055. // RPC call
  16056. ret = ScGetHubAdminOptions(ps->Rpc, &t);
  16057. if (ret != ERR_NO_ERROR)
  16058. {
  16059. // An error has occured
  16060. CmdPrintError(c, ret);
  16061. FreeParamValueList(o);
  16062. return ret;
  16063. }
  16064. else
  16065. {
  16066. UINT i;
  16067. bool b = false;
  16068. for (i = 0;i < t.NumItem;i++)
  16069. {
  16070. if (StrCmpi(t.Items[i].Name, GetParamStr(o, "[name]")) == 0)
  16071. {
  16072. t.Items[i].Value = GetParamInt(o, "VALUE");
  16073. b = true;
  16074. }
  16075. }
  16076. if (b == false)
  16077. {
  16078. // An error has occured
  16079. ret = ERR_OBJECT_NOT_FOUND;
  16080. CmdPrintError(c, ret);
  16081. FreeParamValueList(o);
  16082. FreeRpcAdminOption(&t);
  16083. return ret;
  16084. }
  16085. else
  16086. {
  16087. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16088. ret = ScSetHubAdminOptions(ps->Rpc, &t);
  16089. if (ret != ERR_NO_ERROR)
  16090. {
  16091. // An error has occured
  16092. CmdPrintError(c, ret);
  16093. FreeParamValueList(o);
  16094. return ret;
  16095. }
  16096. }
  16097. }
  16098. FreeRpcAdminOption(&t);
  16099. FreeParamValueList(o);
  16100. return 0;
  16101. }
  16102. // Get the list of Virtual HUB extended options
  16103. UINT PsExtOptionList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16104. {
  16105. LIST *o;
  16106. PS *ps = (PS *)param;
  16107. UINT ret = 0;
  16108. RPC_ADMIN_OPTION t;
  16109. // If virtual HUB is not selected, it's an error
  16110. if (ps->HubName == NULL)
  16111. {
  16112. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  16113. return ERR_INVALID_PARAMETER;
  16114. }
  16115. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  16116. if (o == NULL)
  16117. {
  16118. return ERR_INVALID_PARAMETER;
  16119. }
  16120. Zero(&t, sizeof(t));
  16121. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16122. // RPC call
  16123. ret = ScGetHubExtOptions(ps->Rpc, &t);
  16124. if (ret != ERR_NO_ERROR)
  16125. {
  16126. // An error has occured
  16127. CmdPrintError(c, ret);
  16128. FreeParamValueList(o);
  16129. return ret;
  16130. }
  16131. else
  16132. {
  16133. CT *ct = CtNewStandardEx();
  16134. UINT i;
  16135. for (i = 0;i < t.NumItem;i++)
  16136. {
  16137. ADMIN_OPTION *e = &t.Items[i];
  16138. wchar_t tmp1[MAX_SIZE];
  16139. wchar_t tmp2[MAX_SIZE];
  16140. StrToUni(tmp1, sizeof(tmp1), e->Name);
  16141. UniToStru(tmp2, e->Value);
  16142. CtInsert(ct, tmp1, tmp2, GetHubAdminOptionHelpString(e->Name));
  16143. }
  16144. CtFreeEx(ct, c, true);
  16145. }
  16146. FreeRpcAdminOption(&t);
  16147. FreeParamValueList(o);
  16148. return 0;
  16149. }
  16150. // Set the value of a Virtual HUB extended option
  16151. UINT PsExtOptionSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16152. {
  16153. LIST *o;
  16154. PS *ps = (PS *)param;
  16155. UINT ret = 0;
  16156. RPC_ADMIN_OPTION t;
  16157. // Parameter list that can be specified
  16158. PARAM args[] =
  16159. {
  16160. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  16161. {"[name]", CmdPrompt, _UU("CMD_AdminOptionSet_Prompt_name"), CmdEvalNotEmpty, NULL},
  16162. {"VALUE", CmdPrompt, _UU("CMD_AdminOptionSet_Prompt_VALUE"), CmdEvalNotEmpty, NULL},
  16163. };
  16164. // If virtual HUB is not selected, it's an error
  16165. if (ps->HubName == NULL)
  16166. {
  16167. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  16168. return ERR_INVALID_PARAMETER;
  16169. }
  16170. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  16171. if (o == NULL)
  16172. {
  16173. return ERR_INVALID_PARAMETER;
  16174. }
  16175. Zero(&t, sizeof(t));
  16176. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16177. // RPC call
  16178. ret = ScGetHubExtOptions(ps->Rpc, &t);
  16179. if (ret != ERR_NO_ERROR)
  16180. {
  16181. // An error has occured
  16182. CmdPrintError(c, ret);
  16183. FreeParamValueList(o);
  16184. return ret;
  16185. }
  16186. else
  16187. {
  16188. UINT i;
  16189. bool b = false;
  16190. for (i = 0;i < t.NumItem;i++)
  16191. {
  16192. if (StrCmpi(t.Items[i].Name, GetParamStr(o, "[name]")) == 0)
  16193. {
  16194. t.Items[i].Value = GetParamInt(o, "VALUE");
  16195. b = true;
  16196. }
  16197. }
  16198. if (b == false)
  16199. {
  16200. // An error has occured
  16201. ret = ERR_OBJECT_NOT_FOUND;
  16202. CmdPrintError(c, ret);
  16203. FreeParamValueList(o);
  16204. FreeRpcAdminOption(&t);
  16205. return ret;
  16206. }
  16207. else
  16208. {
  16209. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16210. ret = ScSetHubExtOptions(ps->Rpc, &t);
  16211. if (ret != ERR_NO_ERROR)
  16212. {
  16213. // An error has occured
  16214. CmdPrintError(c, ret);
  16215. FreeParamValueList(o);
  16216. return ret;
  16217. }
  16218. }
  16219. }
  16220. FreeRpcAdminOption(&t);
  16221. FreeParamValueList(o);
  16222. return 0;
  16223. }
  16224. // Get the list of revoked certificate list
  16225. UINT PsCrlList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16226. {
  16227. LIST *o;
  16228. PS *ps = (PS *)param;
  16229. UINT ret = 0;
  16230. RPC_ENUM_CRL t;
  16231. // If virtual HUB is not selected, it's an error
  16232. if (ps->HubName == NULL)
  16233. {
  16234. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  16235. return ERR_INVALID_PARAMETER;
  16236. }
  16237. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  16238. if (o == NULL)
  16239. {
  16240. return ERR_INVALID_PARAMETER;
  16241. }
  16242. Zero(&t, sizeof(t));
  16243. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16244. // RPC call
  16245. ret = ScEnumCrl(ps->Rpc, &t);
  16246. if (ret != ERR_NO_ERROR)
  16247. {
  16248. // An error has occured
  16249. CmdPrintError(c, ret);
  16250. FreeParamValueList(o);
  16251. return ret;
  16252. }
  16253. else
  16254. {
  16255. UINT i;
  16256. CT *ct = CtNew();
  16257. CtInsertColumn(ct, _UU("CMD_ID"), false);
  16258. CtInsertColumn(ct, _UU("SM_CRL_COLUMN_1"), false);
  16259. for (i = 0;i < t.NumItem;i++)
  16260. {
  16261. wchar_t tmp[64];
  16262. RPC_ENUM_CRL_ITEM *e = &t.Items[i];
  16263. UniToStru(tmp, e->Key);
  16264. CtInsert(ct, tmp, e->CrlInfo);
  16265. }
  16266. CtFreeEx(ct, c, true);
  16267. }
  16268. FreeRpcEnumCrl(&t);
  16269. FreeParamValueList(o);
  16270. return 0;
  16271. }
  16272. // Add a revoked certificate
  16273. UINT PsCrlAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16274. {
  16275. LIST *o;
  16276. PS *ps = (PS *)param;
  16277. UINT ret = 0;
  16278. RPC_CRL t;
  16279. // Parameter list that can be specified
  16280. PARAM args[] =
  16281. {
  16282. {"SERIAL", NULL, NULL, NULL, NULL},
  16283. {"MD5", NULL, NULL, NULL, NULL},
  16284. {"SHA1", NULL, NULL, NULL, NULL},
  16285. {"CN", NULL, NULL, NULL, NULL},
  16286. {"O", NULL, NULL, NULL, NULL},
  16287. {"OU", NULL, NULL, NULL, NULL},
  16288. {"C", NULL, NULL, NULL, NULL},
  16289. {"ST", NULL, NULL, NULL, NULL},
  16290. {"L", NULL, NULL, NULL, NULL},
  16291. };
  16292. // If virtual HUB is not selected, it's an error
  16293. if (ps->HubName == NULL)
  16294. {
  16295. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  16296. return ERR_INVALID_PARAMETER;
  16297. }
  16298. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  16299. if (o == NULL)
  16300. {
  16301. return ERR_INVALID_PARAMETER;
  16302. }
  16303. Zero(&t, sizeof(t));
  16304. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16305. {
  16306. bool param_exists = false;
  16307. CRL *crl = ZeroMalloc(sizeof(CRL));
  16308. NAME *n;
  16309. n = crl->Name = ZeroMalloc(sizeof(NAME));
  16310. if (IsEmptyStr(GetParamStr(o, "CN")) == false)
  16311. {
  16312. n->CommonName = CopyUniStr(GetParamUniStr(o, "CN"));
  16313. param_exists = true;
  16314. }
  16315. if (IsEmptyStr(GetParamStr(o, "O")) == false)
  16316. {
  16317. n->CommonName = CopyUniStr(GetParamUniStr(o, "O"));
  16318. param_exists = true;
  16319. }
  16320. if (IsEmptyStr(GetParamStr(o, "OU")) == false)
  16321. {
  16322. n->CommonName = CopyUniStr(GetParamUniStr(o, "OU"));
  16323. param_exists = true;
  16324. }
  16325. if (IsEmptyStr(GetParamStr(o, "C")) == false)
  16326. {
  16327. n->CommonName = CopyUniStr(GetParamUniStr(o, "C"));
  16328. param_exists = true;
  16329. }
  16330. if (IsEmptyStr(GetParamStr(o, "ST")) == false)
  16331. {
  16332. n->CommonName = CopyUniStr(GetParamUniStr(o, "ST"));
  16333. param_exists = true;
  16334. }
  16335. if (IsEmptyStr(GetParamStr(o, "L")) == false)
  16336. {
  16337. n->CommonName = CopyUniStr(GetParamUniStr(o, "L"));
  16338. param_exists = true;
  16339. }
  16340. if (IsEmptyStr(GetParamStr(o, "SERIAL")) == false)
  16341. {
  16342. BUF *b;
  16343. b = StrToBin(GetParamStr(o, "SERIAL"));
  16344. if (b != NULL && b->Size >= 1)
  16345. {
  16346. crl->Serial = NewXSerial(b->Buf, b->Size);
  16347. param_exists = true;
  16348. }
  16349. FreeBuf(b);
  16350. }
  16351. if (IsEmptyStr(GetParamStr(o, "MD5")) == false)
  16352. {
  16353. BUF *b;
  16354. b = StrToBin(GetParamStr(o, "MD5"));
  16355. if (b != NULL && b->Size == MD5_SIZE)
  16356. {
  16357. Copy(crl->DigestMD5, b->Buf, MD5_SIZE);
  16358. param_exists = true;
  16359. }
  16360. FreeBuf(b);
  16361. }
  16362. if (IsEmptyStr(GetParamStr(o, "SHA1")) == false)
  16363. {
  16364. BUF *b;
  16365. b = StrToBin(GetParamStr(o, "SHA1"));
  16366. if (b != NULL && b->Size == SHA1_SIZE)
  16367. {
  16368. Copy(crl->DigestSHA1, b->Buf, SHA1_SIZE);
  16369. param_exists = true;
  16370. }
  16371. FreeBuf(b);
  16372. }
  16373. t.Crl = crl;
  16374. if (param_exists == false)
  16375. {
  16376. FreeRpcCrl(&t);
  16377. ret = ERR_INVALID_PARAMETER;
  16378. CmdPrintError(c, ret);
  16379. FreeParamValueList(o);
  16380. return ret;
  16381. }
  16382. }
  16383. // RPC call
  16384. ret = ScAddCrl(ps->Rpc, &t);
  16385. if (ret != ERR_NO_ERROR)
  16386. {
  16387. // An error has occured
  16388. CmdPrintError(c, ret);
  16389. FreeParamValueList(o);
  16390. return ret;
  16391. }
  16392. FreeRpcCrl(&t);
  16393. FreeParamValueList(o);
  16394. return 0;
  16395. }
  16396. // Delete the revoked certificate
  16397. UINT PsCrlDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16398. {
  16399. LIST *o;
  16400. PS *ps = (PS *)param;
  16401. UINT ret = 0;
  16402. RPC_CRL t;
  16403. // Parameter list that can be specified
  16404. PARAM args[] =
  16405. {
  16406. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  16407. {"[id]", CmdPrompt, _UU("CMD_CrlDel_Prompt_ID"), CmdEvalNotEmpty, NULL},
  16408. };
  16409. // If virtual HUB is not selected, it's an error
  16410. if (ps->HubName == NULL)
  16411. {
  16412. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  16413. return ERR_INVALID_PARAMETER;
  16414. }
  16415. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  16416. if (o == NULL)
  16417. {
  16418. return ERR_INVALID_PARAMETER;
  16419. }
  16420. Zero(&t, sizeof(t));
  16421. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16422. t.Key = GetParamInt(o, "[id]");
  16423. // RPC call
  16424. ret = ScDelCrl(ps->Rpc, &t);
  16425. if (ret != ERR_NO_ERROR)
  16426. {
  16427. // An error has occured
  16428. CmdPrintError(c, ret);
  16429. FreeParamValueList(o);
  16430. return ret;
  16431. }
  16432. FreeRpcCrl(&t);
  16433. FreeParamValueList(o);
  16434. return 0;
  16435. }
  16436. // Get the revoked certificate
  16437. UINT PsCrlGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16438. {
  16439. LIST *o;
  16440. PS *ps = (PS *)param;
  16441. UINT ret = 0;
  16442. RPC_CRL t;
  16443. // Parameter list that can be specified
  16444. PARAM args[] =
  16445. {
  16446. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  16447. {"[id]", CmdPrompt, _UU("CMD_CrlGet_Prompt_ID"), CmdEvalNotEmpty, NULL},
  16448. };
  16449. // If virtual HUB is not selected, it's an error
  16450. if (ps->HubName == NULL)
  16451. {
  16452. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  16453. return ERR_INVALID_PARAMETER;
  16454. }
  16455. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  16456. if (o == NULL)
  16457. {
  16458. return ERR_INVALID_PARAMETER;
  16459. }
  16460. Zero(&t, sizeof(t));
  16461. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16462. t.Key = GetParamInt(o, "[id]");
  16463. // RPC call
  16464. ret = ScGetCrl(ps->Rpc, &t);
  16465. if (ret != ERR_NO_ERROR)
  16466. {
  16467. // An error has occured
  16468. CmdPrintError(c, ret);
  16469. FreeParamValueList(o);
  16470. return ret;
  16471. }
  16472. else
  16473. {
  16474. // Show contents
  16475. CT *ct = CtNewStandard();
  16476. CRL *crl = t.Crl;
  16477. NAME *n;
  16478. if (crl != NULL)
  16479. {
  16480. n = crl->Name;
  16481. if (n != NULL)
  16482. {
  16483. if (UniIsEmptyStr(n->CommonName) == false)
  16484. {
  16485. CtInsert(ct, _UU("CMD_CrlGet_CN"), n->CommonName);
  16486. }
  16487. if (UniIsEmptyStr(n->Organization) == false)
  16488. {
  16489. CtInsert(ct, _UU("CMD_CrlGet_O"), n->Organization);
  16490. }
  16491. if (UniIsEmptyStr(n->Unit) == false)
  16492. {
  16493. CtInsert(ct, _UU("CMD_CrlGet_OU"), n->Unit);
  16494. }
  16495. if (UniIsEmptyStr(n->Country) == false)
  16496. {
  16497. CtInsert(ct, _UU("CMD_CrlGet_C"), n->Country);
  16498. }
  16499. if (UniIsEmptyStr(n->State) == false)
  16500. {
  16501. CtInsert(ct, _UU("CMD_CrlGet_ST"), n->State);
  16502. }
  16503. if (UniIsEmptyStr(n->Local) == false)
  16504. {
  16505. CtInsert(ct, _UU("CMD_CrlGet_L"), n->Local);
  16506. }
  16507. }
  16508. if (crl->Serial != NULL && crl->Serial->size >= 1)
  16509. {
  16510. wchar_t tmp[MAX_SIZE];
  16511. char str[MAX_SIZE];
  16512. BinToStrEx(str, sizeof(str), crl->Serial->data, crl->Serial->size);
  16513. StrToUni(tmp, sizeof(tmp), str);
  16514. CtInsert(ct, _UU("CMD_CrlGet_SERI"), tmp);
  16515. }
  16516. if (IsZero(crl->DigestMD5, MD5_SIZE) == false)
  16517. {
  16518. wchar_t tmp[MAX_SIZE];
  16519. char str[MAX_SIZE];
  16520. BinToStrEx(str, sizeof(str), crl->DigestMD5, MD5_SIZE);
  16521. StrToUni(tmp, sizeof(tmp), str);
  16522. CtInsert(ct, _UU("CMD_CrlGet_MD5_HASH"), tmp);
  16523. }
  16524. if (IsZero(crl->DigestSHA1, SHA1_SIZE) == false)
  16525. {
  16526. wchar_t tmp[MAX_SIZE];
  16527. char str[MAX_SIZE];
  16528. BinToStrEx(str, sizeof(str), crl->DigestSHA1, SHA1_SIZE);
  16529. StrToUni(tmp, sizeof(tmp), str);
  16530. CtInsert(ct, _UU("CMD_CrlGet_SHA1_HASH"), tmp);
  16531. }
  16532. }
  16533. CtFree(ct, c);
  16534. }
  16535. FreeRpcCrl(&t);
  16536. FreeParamValueList(o);
  16537. return 0;
  16538. }
  16539. // Get the rules of IP access control list
  16540. UINT PsAcList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16541. {
  16542. LIST *o;
  16543. PS *ps = (PS *)param;
  16544. UINT ret = 0;
  16545. RPC_AC_LIST t;
  16546. // If virtual HUB is not selected, it's an error
  16547. if (ps->HubName == NULL)
  16548. {
  16549. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  16550. return ERR_INVALID_PARAMETER;
  16551. }
  16552. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  16553. if (o == NULL)
  16554. {
  16555. return ERR_INVALID_PARAMETER;
  16556. }
  16557. Zero(&t, sizeof(t));
  16558. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16559. // RPC call
  16560. ret = ScGetAcList(ps->Rpc, &t);
  16561. if (ret != ERR_NO_ERROR)
  16562. {
  16563. // An error has occured
  16564. CmdPrintError(c, ret);
  16565. FreeParamValueList(o);
  16566. return ret;
  16567. }
  16568. else
  16569. {
  16570. UINT i;
  16571. CT *ct;
  16572. ct = CtNew();
  16573. CtInsertColumn(ct, _UU("SM_AC_COLUMN_1"), true);
  16574. CtInsertColumn(ct, _UU("SM_AC_COLUMN_2"), true);
  16575. CtInsertColumn(ct, _UU("SM_AC_COLUMN_3"), false);
  16576. CtInsertColumn(ct, _UU("SM_AC_COLUMN_4"), false);
  16577. for (i = 0;i < LIST_NUM(t.o);i++)
  16578. {
  16579. wchar_t tmp1[32], *tmp2, tmp3[MAX_SIZE], tmp4[32];
  16580. char *tmp_str;
  16581. AC *ac = LIST_DATA(t.o, i);
  16582. UniToStru(tmp1, ac->Id);
  16583. tmp2 = ac->Deny ? _UU("SM_AC_DENY") : _UU("SM_AC_PASS");
  16584. tmp_str = GenerateAcStr(ac);
  16585. StrToUni(tmp3, sizeof(tmp3), tmp_str);
  16586. Free(tmp_str);
  16587. UniToStru(tmp4, ac->Priority);
  16588. CtInsert(ct, tmp1, tmp4, tmp2, tmp3);
  16589. }
  16590. CtFree(ct, c);
  16591. }
  16592. FreeRpcAcList(&t);
  16593. FreeParamValueList(o);
  16594. return 0;
  16595. }
  16596. // Add a rule to the IP access control list (IPv4)
  16597. UINT PsAcAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16598. {
  16599. LIST *o;
  16600. PS *ps = (PS *)param;
  16601. UINT ret = 0;
  16602. RPC_AC_LIST t;
  16603. // Parameter list that can be specified
  16604. CMD_EVAL_MIN_MAX mm =
  16605. {
  16606. "CMD_AcAdd_Eval_PRIORITY", 1, 4294967295UL,
  16607. };
  16608. PARAM args[] =
  16609. {
  16610. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  16611. {"[allow|deny]", CmdPrompt, _UU("CMD_AcAdd_Prompt_AD"), CmdEvalNotEmpty, NULL},
  16612. {"PRIORITY", CmdPrompt, _UU("CMD_AcAdd_Prompt_PRIORITY"), CmdEvalMinMax, &mm},
  16613. {"IP", CmdPrompt, _UU("CMD_AcAdd_Prompt_IP"), CmdEvalIpAndMask4, NULL},
  16614. };
  16615. // If virtual HUB is not selected, it's an error
  16616. if (ps->HubName == NULL)
  16617. {
  16618. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  16619. return ERR_INVALID_PARAMETER;
  16620. }
  16621. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  16622. if (o == NULL)
  16623. {
  16624. return ERR_INVALID_PARAMETER;
  16625. }
  16626. Zero(&t, sizeof(t));
  16627. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16628. // RPC call
  16629. ret = ScGetAcList(ps->Rpc, &t);
  16630. if (ret != ERR_NO_ERROR)
  16631. {
  16632. // An error has occured
  16633. CmdPrintError(c, ret);
  16634. FreeParamValueList(o);
  16635. return ret;
  16636. }
  16637. else
  16638. {
  16639. // Add a new item to the list
  16640. AC *ac = ZeroMalloc(sizeof(AC));
  16641. char *test = GetParamStr(o, "[allow|deny]");
  16642. UINT u_ip, u_mask;
  16643. if (StartWith("deny", test))
  16644. {
  16645. ac->Deny = true;
  16646. }
  16647. ParseIpAndMask4(GetParamStr(o, "IP"), &u_ip, &u_mask);
  16648. UINTToIP(&ac->IpAddress, u_ip);
  16649. if (u_mask == 0xffffffff)
  16650. {
  16651. ac->Masked = false;
  16652. }
  16653. else
  16654. {
  16655. ac->Masked = true;
  16656. UINTToIP(&ac->SubnetMask, u_mask);
  16657. }
  16658. ac->Priority = GetParamInt(o, "PRIORITY");
  16659. Insert(t.o, ac);
  16660. ret = ScSetAcList(ps->Rpc, &t);
  16661. if (ret != ERR_NO_ERROR)
  16662. {
  16663. // An error has occured
  16664. CmdPrintError(c, ret);
  16665. FreeParamValueList(o);
  16666. return ret;
  16667. }
  16668. }
  16669. FreeRpcAcList(&t);
  16670. FreeParamValueList(o);
  16671. return 0;
  16672. }
  16673. // Add a rule to the IP access control list (IPv6)
  16674. UINT PsAcAdd6(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16675. {
  16676. LIST *o;
  16677. PS *ps = (PS *)param;
  16678. UINT ret = 0;
  16679. RPC_AC_LIST t;
  16680. // Parameter list that can be specified
  16681. CMD_EVAL_MIN_MAX mm =
  16682. {
  16683. "CMD_AcAdd6_Eval_PRIORITY", 1, 4294967295UL,
  16684. };
  16685. PARAM args[] =
  16686. {
  16687. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  16688. {"[allow|deny]", CmdPrompt, _UU("CMD_AcAdd6_Prompt_AD"), CmdEvalNotEmpty, NULL},
  16689. {"PRIORITY", CmdPrompt, _UU("CMD_AcAdd6_Prompt_PRIORITY"), CmdEvalMinMax, &mm},
  16690. {"IP", CmdPrompt, _UU("CMD_AcAdd6_Prompt_IP"), CmdEvalIpAndMask6, NULL},
  16691. };
  16692. // If virtual HUB is not selected, it's an error
  16693. if (ps->HubName == NULL)
  16694. {
  16695. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  16696. return ERR_INVALID_PARAMETER;
  16697. }
  16698. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  16699. if (o == NULL)
  16700. {
  16701. return ERR_INVALID_PARAMETER;
  16702. }
  16703. Zero(&t, sizeof(t));
  16704. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16705. // RPC call
  16706. ret = ScGetAcList(ps->Rpc, &t);
  16707. if (ret != ERR_NO_ERROR)
  16708. {
  16709. // An error has occured
  16710. CmdPrintError(c, ret);
  16711. FreeParamValueList(o);
  16712. return ret;
  16713. }
  16714. else
  16715. {
  16716. // Add a new item to the list
  16717. AC *ac = ZeroMalloc(sizeof(AC));
  16718. char *test = GetParamStr(o, "[allow|deny]");
  16719. IP u_ip, u_mask;
  16720. if (StartWith("deny", test))
  16721. {
  16722. ac->Deny = true;
  16723. }
  16724. ParseIpAndMask6(GetParamStr(o, "IP"), &u_ip, &u_mask);
  16725. Copy(&ac->IpAddress, &u_ip, sizeof(IP));
  16726. if (SubnetMaskToInt6(&u_mask) == 128)
  16727. {
  16728. ac->Masked = false;
  16729. }
  16730. else
  16731. {
  16732. ac->Masked = true;
  16733. Copy(&ac->SubnetMask, &u_mask, sizeof(IP));
  16734. }
  16735. ac->Priority = GetParamInt(o, "PRIORITY");
  16736. Insert(t.o, ac);
  16737. ret = ScSetAcList(ps->Rpc, &t);
  16738. if (ret != ERR_NO_ERROR)
  16739. {
  16740. // An error has occured
  16741. CmdPrintError(c, ret);
  16742. FreeParamValueList(o);
  16743. return ret;
  16744. }
  16745. }
  16746. FreeRpcAcList(&t);
  16747. FreeParamValueList(o);
  16748. return 0;
  16749. }
  16750. // Run the debug command
  16751. UINT PsDebug(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16752. {
  16753. LIST *o;
  16754. PS *ps = (PS *)param;
  16755. UINT ret = 0;
  16756. UINT id;
  16757. // Parameter list that can be specified
  16758. PARAM args[] =
  16759. {
  16760. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  16761. {"[id]", NULL, NULL, NULL, NULL},
  16762. {"ARG", NULL, NULL, NULL, NULL},
  16763. };
  16764. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  16765. if (o == NULL)
  16766. {
  16767. return ERR_INVALID_PARAMETER;
  16768. }
  16769. id = GetParamInt(o, "[id]");
  16770. if (true)
  16771. {
  16772. RPC_TEST t;
  16773. UINT ret;
  16774. c->Write(c, _UU("CMD_Debug_Msg1"));
  16775. Zero(&t, sizeof(t));
  16776. t.IntValue = id;
  16777. StrCpy(t.StrValue, sizeof(t.StrValue), GetParamStr(o, "ARG"));
  16778. ret = ScDebug(ps->Rpc, &t);
  16779. if (ret != ERR_NO_ERROR)
  16780. {
  16781. // An error has occured
  16782. CmdPrintError(c, ret);
  16783. FreeParamValueList(o);
  16784. return ret;
  16785. }
  16786. else
  16787. {
  16788. wchar_t tmp[sizeof(t.StrValue)];
  16789. UniFormat(tmp, sizeof(tmp), _UU("CMD_Debug_Msg2"), t.StrValue);
  16790. c->Write(c, tmp);
  16791. }
  16792. }
  16793. FreeParamValueList(o);
  16794. return 0;
  16795. }
  16796. // Flush the configuration file on the server
  16797. UINT PsFlush(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16798. {
  16799. LIST *o;
  16800. PS *ps = (PS *)param;
  16801. UINT ret = 0;
  16802. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  16803. if (o == NULL)
  16804. {
  16805. return ERR_INVALID_PARAMETER;
  16806. }
  16807. if (true)
  16808. {
  16809. RPC_TEST t;
  16810. UINT ret;
  16811. wchar_t tmp[MAX_SIZE];
  16812. char sizestr[MAX_SIZE];
  16813. c->Write(c, _UU("CMD_Flush_Msg1"));
  16814. Zero(&t, sizeof(t));
  16815. ret = ScFlush(ps->Rpc, &t);
  16816. if (ret != ERR_NO_ERROR)
  16817. {
  16818. // An error has occured
  16819. CmdPrintError(c, ret);
  16820. FreeParamValueList(o);
  16821. return ret;
  16822. }
  16823. ToStr3(sizestr, sizeof(sizestr), (UINT64)t.IntValue);
  16824. UniFormat(tmp, sizeof(tmp), _UU("CMD_Flush_Msg2"), sizestr);
  16825. c->Write(c, tmp);
  16826. }
  16827. FreeParamValueList(o);
  16828. return 0;
  16829. }
  16830. // Crash
  16831. UINT PsCrash(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16832. {
  16833. LIST *o;
  16834. PS *ps = (PS *)param;
  16835. UINT ret = 0;
  16836. char *yes;
  16837. // Parameter list that can be specified
  16838. PARAM args[] =
  16839. {
  16840. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  16841. {"[yes]", CmdPrompt, _UU("CMD_Crash_Confirm"), NULL, NULL},
  16842. };
  16843. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  16844. if (o == NULL)
  16845. {
  16846. return ERR_INVALID_PARAMETER;
  16847. }
  16848. yes = GetParamStr(o, "[yes]");
  16849. if (StrCmpi(yes, "yes") != 0)
  16850. {
  16851. c->Write(c, _UU("CMD_Crash_Aborted"));
  16852. }
  16853. else
  16854. {
  16855. RPC_TEST t;
  16856. UINT ret;
  16857. c->Write(c, _UU("CMD_Crash_Msg"));
  16858. Zero(&t, sizeof(t));
  16859. ret = ScCrash(ps->Rpc, &t);
  16860. if (ret != ERR_NO_ERROR)
  16861. {
  16862. // An error has occured
  16863. CmdPrintError(c, ret);
  16864. FreeParamValueList(o);
  16865. return ret;
  16866. }
  16867. }
  16868. FreeParamValueList(o);
  16869. return 0;
  16870. }
  16871. // Remove a rule in the IP access control list
  16872. UINT PsAcDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16873. {
  16874. LIST *o;
  16875. PS *ps = (PS *)param;
  16876. UINT ret = 0;
  16877. RPC_AC_LIST t;
  16878. // Parameter list that can be specified
  16879. PARAM args[] =
  16880. {
  16881. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  16882. {"[id]", CmdPrompt, _UU("CMD_AcDel_Prompt_ID"), CmdEvalNotEmpty, NULL},
  16883. };
  16884. // If virtual HUB is not selected, it's an error
  16885. if (ps->HubName == NULL)
  16886. {
  16887. c->Write(c, _UU("CMD_Hub_Not_Selected"));
  16888. return ERR_INVALID_PARAMETER;
  16889. }
  16890. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  16891. if (o == NULL)
  16892. {
  16893. return ERR_INVALID_PARAMETER;
  16894. }
  16895. Zero(&t, sizeof(t));
  16896. StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
  16897. // RPC call
  16898. ret = ScGetAcList(ps->Rpc, &t);
  16899. if (ret != ERR_NO_ERROR)
  16900. {
  16901. // An error has occured
  16902. CmdPrintError(c, ret);
  16903. FreeParamValueList(o);
  16904. return ret;
  16905. }
  16906. else
  16907. {
  16908. // Remove matched ID
  16909. UINT i;
  16910. bool b = false;
  16911. for (i = 0;i < LIST_NUM(t.o);i++)
  16912. {
  16913. AC *ac = LIST_DATA(t.o, i);
  16914. if (ac->Id == GetParamInt(o, "[id]"))
  16915. {
  16916. Delete(t.o, ac);
  16917. Free(ac);
  16918. b = true;
  16919. break;
  16920. }
  16921. }
  16922. if (b == false)
  16923. {
  16924. ret = ERR_OBJECT_NOT_FOUND;
  16925. FreeRpcAcList(&t);
  16926. }
  16927. else
  16928. {
  16929. ret = ScSetAcList(ps->Rpc, &t);
  16930. }
  16931. if (ret != ERR_NO_ERROR)
  16932. {
  16933. // An error has occured
  16934. CmdPrintError(c, ret);
  16935. FreeParamValueList(o);
  16936. return ret;
  16937. }
  16938. }
  16939. FreeRpcAcList(&t);
  16940. FreeParamValueList(o);
  16941. return 0;
  16942. }
  16943. // Enable / Disable the IPsec VPN server function
  16944. UINT PsIPsecEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16945. {
  16946. LIST *o;
  16947. PS *ps = (PS *)param;
  16948. UINT ret = 0;
  16949. IPSEC_SERVICES t;
  16950. // Parameter list that can be specified
  16951. PARAM args[] =
  16952. {
  16953. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  16954. {"L2TP", CmdPrompt, _UU("CMD_IPsecEnable_Prompt_L2TP"), CmdEvalNotEmpty, NULL},
  16955. {"L2TPRAW", CmdPrompt, _UU("CMD_IPsecEnable_Prompt_L2TPRAW"), CmdEvalNotEmpty, NULL},
  16956. {"ETHERIP", CmdPrompt, _UU("CMD_IPsecEnable_Prompt_ETHERIP"), CmdEvalNotEmpty, NULL},
  16957. {"PSK", CmdPrompt, _UU("CMD_IPsecEnable_Prompt_PSK"), CmdEvalNotEmpty, NULL},
  16958. {"DEFAULTHUB", CmdPrompt, _UU("CMD_IPsecEnable_Prompt_DEFAULTHUB"), CmdEvalNotEmpty, NULL},
  16959. };
  16960. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  16961. if (o == NULL)
  16962. {
  16963. return ERR_INVALID_PARAMETER;
  16964. }
  16965. Zero(&t, sizeof(t));
  16966. t.L2TP_IPsec = GetParamYes(o, "L2TP");
  16967. t.L2TP_Raw = GetParamYes(o, "L2TPRAW");
  16968. t.EtherIP_IPsec = GetParamYes(o, "ETHERIP");
  16969. StrCpy(t.IPsec_Secret, sizeof(t.IPsec_Secret), GetParamStr(o, "PSK"));
  16970. StrCpy(t.L2TP_DefaultHub, sizeof(t.L2TP_DefaultHub), GetParamStr(o, "DEFAULTHUB"));
  16971. // RPC call
  16972. ret = ScSetIPsecServices(ps->Rpc, &t);
  16973. if (ret != ERR_NO_ERROR)
  16974. {
  16975. // An error has occured
  16976. CmdPrintError(c, ret);
  16977. FreeParamValueList(o);
  16978. return ret;
  16979. }
  16980. FreeParamValueList(o);
  16981. return 0;
  16982. }
  16983. // Get the current configuration of IPsec VPN server function
  16984. UINT PsIPsecGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  16985. {
  16986. LIST *o;
  16987. PS *ps = (PS *)param;
  16988. UINT ret = 0;
  16989. IPSEC_SERVICES t;
  16990. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  16991. if (o == NULL)
  16992. {
  16993. return ERR_INVALID_PARAMETER;
  16994. }
  16995. Zero(&t, sizeof(t));
  16996. // RPC call
  16997. ret = ScGetIPsecServices(ps->Rpc, &t);
  16998. if (ret != ERR_NO_ERROR)
  16999. {
  17000. // An error has occured
  17001. CmdPrintError(c, ret);
  17002. FreeParamValueList(o);
  17003. return ret;
  17004. }
  17005. else
  17006. {
  17007. wchar_t tmp[MAX_PATH];
  17008. CT *ct = CtNewStandard();
  17009. CtInsert(ct, _UU("CMD_IPsecGet_PRINT_L2TP"), _UU(t.L2TP_IPsec ? "SEC_YES" : "SEC_NO"));
  17010. CtInsert(ct, _UU("CMD_IPsecGet_PRINT_L2TPRAW"), _UU(t.L2TP_Raw ? "SEC_YES" : "SEC_NO"));
  17011. CtInsert(ct, _UU("CMD_IPsecGet_PRINT_ETHERIP"), _UU(t.EtherIP_IPsec ? "SEC_YES" : "SEC_NO"));
  17012. StrToUni(tmp, sizeof(tmp), t.IPsec_Secret);
  17013. CtInsert(ct, _UU("CMD_IPsecGet_PRINT_PSK"), tmp);
  17014. StrToUni(tmp, sizeof(tmp), t.L2TP_DefaultHub);
  17015. CtInsert(ct, _UU("CMD_IPsecGet_PRINT_DEFAULTHUB"), tmp);
  17016. CtFree(ct, c);
  17017. }
  17018. FreeParamValueList(o);
  17019. return 0;
  17020. }
  17021. // Add connection settings for accepting connections from client devices of EtherIP / L2TPv3 over IPsec server function
  17022. UINT PsEtherIpClientAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17023. {
  17024. LIST *o;
  17025. PS *ps = (PS *)param;
  17026. UINT ret = 0;
  17027. ETHERIP_ID t;
  17028. // Parameter list that can be specified
  17029. PARAM args[] =
  17030. {
  17031. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  17032. {"[ID]", CmdPrompt, _UU("CMD_EtherIpClientAdd_Prompt_ID"), CmdEvalNotEmpty, NULL},
  17033. {"HUB", CmdPrompt, _UU("CMD_EtherIpClientAdd_Prompt_HUB"), CmdEvalNotEmpty, NULL},
  17034. {"USERNAME", CmdPrompt, _UU("CMD_EtherIpClientAdd_Prompt_USERNAME"), CmdEvalNotEmpty, NULL},
  17035. {"PASSWORD", CmdPrompt, _UU("CMD_EtherIpClientAdd_Prompt_PASSWORD"), CmdEvalNotEmpty, NULL},
  17036. };
  17037. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  17038. if (o == NULL)
  17039. {
  17040. return ERR_INVALID_PARAMETER;
  17041. }
  17042. Zero(&t, sizeof(t));
  17043. StrCpy(t.Id, sizeof(t.Id), GetParamStr(o, "[ID]"));
  17044. StrCpy(t.HubName, sizeof(t.HubName), GetParamStr(o, "HUB"));
  17045. StrCpy(t.UserName, sizeof(t.UserName), GetParamStr(o, "USERNAME"));
  17046. StrCpy(t.Password, sizeof(t.Password), GetParamStr(o, "PASSWORD"));
  17047. // RPC call
  17048. ret = ScAddEtherIpId(ps->Rpc, &t);
  17049. if (ret != ERR_NO_ERROR)
  17050. {
  17051. // An error has occured
  17052. CmdPrintError(c, ret);
  17053. FreeParamValueList(o);
  17054. return ret;
  17055. }
  17056. FreeParamValueList(o);
  17057. return 0;
  17058. }
  17059. // Delete the connection settings for accepting connections from client devices of EtherIP / L2TPv3 over IPsec server function
  17060. UINT PsEtherIpClientDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17061. {
  17062. LIST *o;
  17063. PS *ps = (PS *)param;
  17064. UINT ret = 0;
  17065. ETHERIP_ID t;
  17066. // Parameter list that can be specified
  17067. PARAM args[] =
  17068. {
  17069. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  17070. {"[ID]", CmdPrompt, _UU("CMD_EtherIpClientDelete_Prompt_ID"), CmdEvalNotEmpty, NULL},
  17071. };
  17072. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  17073. if (o == NULL)
  17074. {
  17075. return ERR_INVALID_PARAMETER;
  17076. }
  17077. Zero(&t, sizeof(t));
  17078. StrCpy(t.Id, sizeof(t.Id), GetParamStr(o, "[ID]"));
  17079. // RPC call
  17080. ret = ScDeleteEtherIpId(ps->Rpc, &t);
  17081. if (ret != ERR_NO_ERROR)
  17082. {
  17083. // An error has occured
  17084. CmdPrintError(c, ret);
  17085. FreeParamValueList(o);
  17086. return ret;
  17087. }
  17088. FreeParamValueList(o);
  17089. return 0;
  17090. }
  17091. // Show the list of connection settings for accepting connections from client devices of EtherIP / L2TPv3 over IPsec server function
  17092. UINT PsEtherIpClientList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17093. {
  17094. LIST *o;
  17095. PS *ps = (PS *)param;
  17096. UINT ret = 0;
  17097. RPC_ENUM_ETHERIP_ID t;
  17098. UINT i;
  17099. CT *b;
  17100. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  17101. if (o == NULL)
  17102. {
  17103. return ERR_INVALID_PARAMETER;
  17104. }
  17105. Zero(&t, sizeof(t));
  17106. // RPC call
  17107. ret = ScEnumEtherIpId(ps->Rpc, &t);
  17108. if (ret != ERR_NO_ERROR)
  17109. {
  17110. // An error has occured
  17111. CmdPrintError(c, ret);
  17112. FreeParamValueList(o);
  17113. return ret;
  17114. }
  17115. else
  17116. {
  17117. b = CtNew();
  17118. CtInsertColumn(b, _UU("SM_ETHERIP_COLUMN_0"), false);
  17119. CtInsertColumn(b, _UU("SM_ETHERIP_COLUMN_1"), false);
  17120. CtInsertColumn(b, _UU("SM_ETHERIP_COLUMN_2"), false);
  17121. for (i = 0;i < t.NumItem;i++)
  17122. {
  17123. ETHERIP_ID *d = &t.IdList[i];
  17124. wchar_t id[MAX_SIZE], hubname[MAX_SIZE], username[MAX_SIZE];
  17125. StrToUni(id, sizeof(id), d->Id);
  17126. StrToUni(hubname, sizeof(hubname), d->HubName);
  17127. StrToUni(username, sizeof(username), d->UserName);
  17128. CtInsert(b, id, hubname, username);
  17129. }
  17130. CtFree(b, c);
  17131. FreeRpcEnumEtherIpId(&t);
  17132. }
  17133. FreeParamValueList(o);
  17134. return 0;
  17135. }
  17136. // Enable / disable the OpenVPN compatible server function
  17137. UINT PsOpenVpnEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17138. {
  17139. LIST *o;
  17140. PS *ps = (PS *)param;
  17141. UINT ret = 0;
  17142. OPENVPN_SSTP_CONFIG t;
  17143. // Parameter list that can be specified
  17144. PARAM args[] =
  17145. {
  17146. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  17147. {"[yes|no]", CmdPrompt, _UU("CMD_OpenVpnEnable_Prompt_[yes|no]"), CmdEvalNotEmpty, NULL},
  17148. {"PORTS", CmdPrompt, _UU("CMD_OpenVpnEnable_Prompt_PORTS"), CmdEvalNotEmpty, NULL},
  17149. };
  17150. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  17151. if (o == NULL)
  17152. {
  17153. return ERR_INVALID_PARAMETER;
  17154. }
  17155. Zero(&t, sizeof(t));
  17156. // RPC call
  17157. ret = ScGetOpenVpnSstpConfig(ps->Rpc, &t);
  17158. if (ret != ERR_NO_ERROR)
  17159. {
  17160. // An error has occured
  17161. CmdPrintError(c, ret);
  17162. FreeParamValueList(o);
  17163. return ret;
  17164. }
  17165. t.EnableOpenVPN = GetParamYes(o, "[yes|no]");
  17166. StrCpy(t.OpenVPNPortList, sizeof(t.OpenVPNPortList), GetParamStr(o, "PORTS"));
  17167. // RPC call
  17168. ret = ScSetOpenVpnSstpConfig(ps->Rpc, &t);
  17169. if (ret != ERR_NO_ERROR)
  17170. {
  17171. // An error has occured
  17172. CmdPrintError(c, ret);
  17173. FreeParamValueList(o);
  17174. return ret;
  17175. }
  17176. FreeParamValueList(o);
  17177. return 0;
  17178. }
  17179. // Get the current settings for the OpenVPN compatible server function
  17180. UINT PsOpenVpnGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17181. {
  17182. LIST *o;
  17183. PS *ps = (PS *)param;
  17184. UINT ret = 0;
  17185. OPENVPN_SSTP_CONFIG t;
  17186. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  17187. if (o == NULL)
  17188. {
  17189. return ERR_INVALID_PARAMETER;
  17190. }
  17191. Zero(&t, sizeof(t));
  17192. // RPC call
  17193. ret = ScGetOpenVpnSstpConfig(ps->Rpc, &t);
  17194. if (ret != ERR_NO_ERROR)
  17195. {
  17196. // An error has occured
  17197. CmdPrintError(c, ret);
  17198. FreeParamValueList(o);
  17199. return ret;
  17200. }
  17201. else
  17202. {
  17203. wchar_t tmp[MAX_PATH];
  17204. CT *ct = CtNewStandard();
  17205. CtInsert(ct, _UU("CMD_OpenVpnGet_PRINT_Enabled"), _UU(t.EnableOpenVPN ? "SEC_YES" : "SEC_NO"));
  17206. StrToUni(tmp, sizeof(tmp), t.OpenVPNPortList);
  17207. CtInsert(ct, _UU("CMD_OpenVpnGet_PRINT_Ports"), tmp);
  17208. CtFree(ct, c);
  17209. }
  17210. FreeParamValueList(o);
  17211. return 0;
  17212. }
  17213. // Generate a OpenVPN sample configuration file that can connect to the OpenVPN compatible server function
  17214. UINT PsOpenVpnMakeConfig(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17215. {
  17216. LIST *o;
  17217. PS *ps = (PS *)param;
  17218. UINT ret = 0;
  17219. RPC_READ_LOG_FILE t;
  17220. // Parameter list that can be specified
  17221. PARAM args[] =
  17222. {
  17223. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  17224. {"[ZIP_FileName]", CmdPrompt, _UU("CMD_OpenVpnMakeConfig_Prompt_ZIP"), CmdEvalNotEmpty, NULL},
  17225. };
  17226. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  17227. if (o == NULL)
  17228. {
  17229. return ERR_INVALID_PARAMETER;
  17230. }
  17231. Zero(&t, sizeof(t));
  17232. // RPC call
  17233. ret = ScMakeOpenVpnConfigFile(ps->Rpc, &t);
  17234. if (ret != ERR_NO_ERROR)
  17235. {
  17236. // An error has occured
  17237. CmdPrintError(c, ret);
  17238. FreeParamValueList(o);
  17239. return ret;
  17240. }
  17241. else
  17242. {
  17243. // Determine the file name to save
  17244. wchar_t filename[MAX_SIZE];
  17245. wchar_t tmp[MAX_SIZE];
  17246. UniStrCpy(filename, sizeof(filename), GetParamUniStr(o, "[ZIP_FileName]"));
  17247. if (UniEndWith(filename, L".zip") == false)
  17248. {
  17249. UniStrCat(filename, sizeof(filename), L".zip");
  17250. }
  17251. if (DumpBufW(t.Buffer, filename) == false)
  17252. {
  17253. ret = ERR_INTERNAL_ERROR;
  17254. UniFormat(tmp, sizeof(tmp), _UU("CMD_OpenVpnMakeConfig_ERROR"), filename);
  17255. }
  17256. else
  17257. {
  17258. UniFormat(tmp, sizeof(tmp), _UU("CMD_OpenVpnMakeConfig_OK"), filename);
  17259. }
  17260. c->Write(c, tmp);
  17261. FreeRpcReadLogFile(&t);
  17262. }
  17263. FreeParamValueList(o);
  17264. return ret;
  17265. }
  17266. // Enable / disable the Microsoft SSTP VPN compatible server function
  17267. UINT PsSstpEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17268. {
  17269. LIST *o;
  17270. PS *ps = (PS *)param;
  17271. UINT ret = 0;
  17272. OPENVPN_SSTP_CONFIG t;
  17273. // Parameter list that can be specified
  17274. PARAM args[] =
  17275. {
  17276. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  17277. {"[yes|no]", CmdPrompt, _UU("CMD_SstpEnable_Prompt_[yes|no]"), CmdEvalNotEmpty, NULL},
  17278. };
  17279. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  17280. if (o == NULL)
  17281. {
  17282. return ERR_INVALID_PARAMETER;
  17283. }
  17284. Zero(&t, sizeof(t));
  17285. // RPC call
  17286. ret = ScGetOpenVpnSstpConfig(ps->Rpc, &t);
  17287. if (ret != ERR_NO_ERROR)
  17288. {
  17289. // An error has occured
  17290. CmdPrintError(c, ret);
  17291. FreeParamValueList(o);
  17292. return ret;
  17293. }
  17294. t.EnableSSTP = GetParamYes(o, "[yes|no]");
  17295. // RPC call
  17296. ret = ScSetOpenVpnSstpConfig(ps->Rpc, &t);
  17297. if (ret != ERR_NO_ERROR)
  17298. {
  17299. // An error has occured
  17300. CmdPrintError(c, ret);
  17301. FreeParamValueList(o);
  17302. return ret;
  17303. }
  17304. FreeParamValueList(o);
  17305. return 0;
  17306. }
  17307. // Get the current settings for the Microsoft SSTP VPN compatible server function
  17308. UINT PsSstpGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17309. {
  17310. LIST *o;
  17311. PS *ps = (PS *)param;
  17312. UINT ret = 0;
  17313. OPENVPN_SSTP_CONFIG t;
  17314. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  17315. if (o == NULL)
  17316. {
  17317. return ERR_INVALID_PARAMETER;
  17318. }
  17319. Zero(&t, sizeof(t));
  17320. // RPC call
  17321. ret = ScGetOpenVpnSstpConfig(ps->Rpc, &t);
  17322. if (ret != ERR_NO_ERROR)
  17323. {
  17324. // An error has occured
  17325. CmdPrintError(c, ret);
  17326. FreeParamValueList(o);
  17327. return ret;
  17328. }
  17329. else
  17330. {
  17331. CT *ct = CtNewStandard();
  17332. CtInsert(ct, _UU("CMD_SstpEnable_PRINT_Enabled"), _UU(t.EnableSSTP ? "SEC_YES" : "SEC_NO"));
  17333. CtFree(ct, c);
  17334. }
  17335. FreeParamValueList(o);
  17336. return 0;
  17337. }
  17338. // Register to the VPN Server by creating a new self-signed certificate with the specified CN (Common Name)
  17339. UINT PsServerCertRegenerate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17340. {
  17341. LIST *o;
  17342. PS *ps = (PS *)param;
  17343. UINT ret = 0;
  17344. RPC_TEST t;
  17345. // Parameter list that can be specified
  17346. PARAM args[] =
  17347. {
  17348. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  17349. {"[CN]", CmdPrompt, _UU("CMD_ServerCertRegenerate_Prompt_CN"), CmdEvalNotEmpty, NULL},
  17350. };
  17351. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  17352. if (o == NULL)
  17353. {
  17354. return ERR_INVALID_PARAMETER;
  17355. }
  17356. Zero(&t, sizeof(t));
  17357. StrCpy(t.StrValue, sizeof(t.StrValue), GetParamStr(o, "[CN]"));
  17358. // RPC call
  17359. ret = ScRegenerateServerCert(ps->Rpc, &t);
  17360. if (ret != ERR_NO_ERROR)
  17361. {
  17362. // An error has occured
  17363. CmdPrintError(c, ret);
  17364. FreeParamValueList(o);
  17365. return ret;
  17366. }
  17367. c->Write(c, L"");
  17368. c->Write(c, _UU("CM_CERT_SET_MSG"));
  17369. c->Write(c, L"");
  17370. FreeParamValueList(o);
  17371. return 0;
  17372. }
  17373. // Enable / disable the VPN over ICMP / VPN over DNS server function
  17374. UINT PsVpnOverIcmpDnsEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17375. {
  17376. LIST *o;
  17377. PS *ps = (PS *)param;
  17378. UINT ret = 0;
  17379. RPC_SPECIAL_LISTENER t;
  17380. // Parameter list that can be specified
  17381. PARAM args[] =
  17382. {
  17383. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  17384. {"ICMP", CmdPrompt, _UU("CMD_VpnOverIcmpDnsEnable_Prompt_ICMP"), CmdEvalNotEmpty, NULL},
  17385. {"DNS", CmdPrompt, _UU("CMD_VpnOverIcmpDnsEnable_Prompt_DNS"), CmdEvalNotEmpty, NULL},
  17386. };
  17387. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  17388. if (o == NULL)
  17389. {
  17390. return ERR_INVALID_PARAMETER;
  17391. }
  17392. Zero(&t, sizeof(t));
  17393. t.VpnOverIcmpListener = GetParamYes(o, "ICMP");
  17394. t.VpnOverDnsListener = GetParamYes(o, "DNS");
  17395. // RPC call
  17396. ret = ScSetSpecialListener(ps->Rpc, &t);
  17397. if (ret != ERR_NO_ERROR)
  17398. {
  17399. // An error has occured
  17400. CmdPrintError(c, ret);
  17401. FreeParamValueList(o);
  17402. return ret;
  17403. }
  17404. FreeParamValueList(o);
  17405. return 0;
  17406. }
  17407. // Get current settings of VPN over ICMP / VPN over DNS server function
  17408. UINT PsVpnOverIcmpDnsGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17409. {
  17410. LIST *o;
  17411. PS *ps = (PS *)param;
  17412. UINT ret = 0;
  17413. RPC_SPECIAL_LISTENER t;
  17414. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  17415. if (o == NULL)
  17416. {
  17417. return ERR_INVALID_PARAMETER;
  17418. }
  17419. Zero(&t, sizeof(t));
  17420. // RPC call
  17421. ret = ScGetSpecialListener(ps->Rpc, &t);
  17422. if (ret != ERR_NO_ERROR)
  17423. {
  17424. // An error has occured
  17425. CmdPrintError(c, ret);
  17426. FreeParamValueList(o);
  17427. return ret;
  17428. }
  17429. else
  17430. {
  17431. CT *ct = CtNewStandard();
  17432. CtInsert(ct, _UU("CMD_VpnOverIcmpDnsGet_PRINT_ICMP"), _UU(t.VpnOverIcmpListener ? "SEC_YES" : "SEC_NO"));
  17433. CtInsert(ct, _UU("CMD_VpnOverIcmpDnsGet_PRINT_DNS"), _UU(t.VpnOverDnsListener ? "SEC_YES" : "SEC_NO"));
  17434. CtFree(ct, c);
  17435. }
  17436. FreeParamValueList(o);
  17437. return 0;
  17438. }
  17439. // Enable / disable the VPN Azure function
  17440. UINT PsVpnAzureSetEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17441. {
  17442. LIST *o;
  17443. PS *ps = (PS *)param;
  17444. UINT ret = 0;
  17445. RPC_AZURE_STATUS t;
  17446. // Parameter list that can be specified
  17447. PARAM args[] =
  17448. {
  17449. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  17450. {"[yes|no]", CmdPrompt, _UU("VpnAzureSetEnable_PROMPT"), CmdEvalNotEmpty, NULL},
  17451. };
  17452. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  17453. if (o == NULL)
  17454. {
  17455. return ERR_INVALID_PARAMETER;
  17456. }
  17457. Zero(&t, sizeof(t));
  17458. t.IsEnabled = GetParamYes(o, "[yes|no]");
  17459. // RPC call
  17460. ret = ScSetAzureStatus(ps->Rpc, &t);
  17461. if (ret != ERR_NO_ERROR)
  17462. {
  17463. // An error has occured
  17464. CmdPrintError(c, ret);
  17465. FreeParamValueList(o);
  17466. return ret;
  17467. }
  17468. FreeParamValueList(o);
  17469. return 0;
  17470. }
  17471. // Get the current state of the VPN Azure function
  17472. UINT PsVpnAzureGetStatus(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17473. {
  17474. LIST *o;
  17475. PS *ps = (PS *)param;
  17476. UINT ret = 0;
  17477. RPC_AZURE_STATUS t;
  17478. DDNS_CLIENT_STATUS t2;
  17479. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  17480. if (o == NULL)
  17481. {
  17482. return ERR_INVALID_PARAMETER;
  17483. }
  17484. Zero(&t, sizeof(t));
  17485. Zero(&t2, sizeof(t2));
  17486. // RPC call
  17487. ret = ScGetAzureStatus(ps->Rpc, &t);
  17488. if (ret == ERR_NO_ERROR)
  17489. {
  17490. ret = ScGetDDnsClientStatus(ps->Rpc, &t2);
  17491. }
  17492. if (ret != ERR_NO_ERROR)
  17493. {
  17494. // An error has occured
  17495. CmdPrintError(c, ret);
  17496. FreeParamValueList(o);
  17497. return ret;
  17498. }
  17499. else
  17500. {
  17501. CT *ct = CtNewStandard();
  17502. CtInsert(ct, _UU("CMD_VpnAzureGetStatus_PRINT_ENABLED"), _UU(t.IsEnabled ? "SEC_YES" : "SEC_NO"));
  17503. if (t.IsEnabled)
  17504. {
  17505. wchar_t tmp[MAX_SIZE];
  17506. UniFormat(tmp, sizeof(tmp), L"%S%S", t2.CurrentHostName, AZURE_DOMAIN_SUFFIX);
  17507. CtInsert(ct, _UU("CMD_VpnAzureGetStatus_PRINT_CONNECTED"), _UU(t.IsConnected ? "SEC_YES" : "SEC_NO"));
  17508. CtInsert(ct, _UU("CMD_VpnAzureGetStatus_PRINT_HOSTNAME"), tmp);
  17509. }
  17510. CtFree(ct, c);
  17511. }
  17512. FreeParamValueList(o);
  17513. return 0;
  17514. }
  17515. // Get the current state of the dynamic DNS function
  17516. UINT PsDynamicDnsGetStatus(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17517. {
  17518. LIST *o;
  17519. PS *ps = (PS *)param;
  17520. UINT ret = 0;
  17521. DDNS_CLIENT_STATUS t;
  17522. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  17523. if (o == NULL)
  17524. {
  17525. return ERR_INVALID_PARAMETER;
  17526. }
  17527. Zero(&t, sizeof(t));
  17528. // RPC call
  17529. ret = ScGetDDnsClientStatus(ps->Rpc, &t);
  17530. if (ret != ERR_NO_ERROR)
  17531. {
  17532. // An error has occured
  17533. CmdPrintError(c, ret);
  17534. FreeParamValueList(o);
  17535. return ret;
  17536. }
  17537. else
  17538. {
  17539. CT *ct = CtNewStandard();
  17540. wchar_t tmp[MAX_SIZE];
  17541. // FQDN
  17542. if (IsEmptyStr(t.CurrentFqdn) == false)
  17543. {
  17544. StrToUni(tmp, sizeof(tmp), t.CurrentFqdn);
  17545. }
  17546. else
  17547. {
  17548. UniStrCpy(tmp, sizeof(tmp), _UU("SM_DDNS_FQDN_EMPTY"));
  17549. }
  17550. CtInsert(ct, _UU("CMD_DynamicDnsGetStatus_PRINT_FQDN"), tmp);
  17551. // Hostname
  17552. if (IsEmptyStr(t.CurrentHostName) == false)
  17553. {
  17554. StrToUni(tmp, sizeof(tmp), t.CurrentHostName);
  17555. }
  17556. else
  17557. {
  17558. UniStrCpy(tmp, sizeof(tmp), _UU("SM_DDNS_FQDN_EMPTY"));
  17559. }
  17560. CtInsert(ct, _UU("CMD_DynamicDnsGetStatus_PRINT_HOSTNAME"), tmp);
  17561. // Suffix
  17562. if (IsEmptyStr(t.DnsSuffix) == false)
  17563. {
  17564. StrToUni(tmp, sizeof(tmp), t.DnsSuffix);
  17565. }
  17566. else
  17567. {
  17568. UniStrCpy(tmp, sizeof(tmp), _UU("SM_DDNS_FQDN_EMPTY"));
  17569. }
  17570. CtInsert(ct, _UU("CMD_DynamicDnsGetStatus_PRINT_SUFFIX"), tmp);
  17571. // IPv4
  17572. if (t.Err_IPv4 == ERR_NO_ERROR)
  17573. {
  17574. StrToUni(tmp, sizeof(tmp), t.CurrentIPv4);
  17575. }
  17576. else
  17577. {
  17578. UniStrCpy(tmp, sizeof(tmp), _E(t.Err_IPv4));
  17579. }
  17580. CtInsert(ct, _UU("CMD_DynamicDnsGetStatus_PRINT_IPv4"), tmp);
  17581. // IPv6
  17582. if (t.Err_IPv6 == ERR_NO_ERROR)
  17583. {
  17584. StrToUni(tmp, sizeof(tmp), t.CurrentIPv6);
  17585. }
  17586. else
  17587. {
  17588. UniStrCpy(tmp, sizeof(tmp), _E(t.Err_IPv6));
  17589. }
  17590. CtInsert(ct, _UU("CMD_DynamicDnsGetStatus_PRINT_IPv6"), tmp);
  17591. CtFree(ct, c);
  17592. }
  17593. FreeParamValueList(o);
  17594. return 0;
  17595. }
  17596. // Configure the dynamic DNS host name
  17597. UINT PsDynamicDnsSetHostname(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17598. {
  17599. LIST *o;
  17600. PS *ps = (PS *)param;
  17601. UINT ret = 0;
  17602. RPC_TEST t;
  17603. // Parameter list that can be specified
  17604. PARAM args[] =
  17605. {
  17606. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  17607. {"[hostname]", CmdPrompt, _UU("CMD_DynamicDnsSetHostname_Prompt_hostname"), CmdEvalNotEmpty, NULL},
  17608. };
  17609. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  17610. if (o == NULL)
  17611. {
  17612. return ERR_INVALID_PARAMETER;
  17613. }
  17614. Zero(&t, sizeof(t));
  17615. StrCpy(t.StrValue, sizeof(t.StrValue), GetParamStr(o, "[hostname]"));
  17616. // RPC call
  17617. ret = ScChangeDDnsClientHostname(ps->Rpc, &t);
  17618. if (ret != ERR_NO_ERROR)
  17619. {
  17620. // An error has occured
  17621. CmdPrintError(c, ret);
  17622. FreeParamValueList(o);
  17623. return ret;
  17624. }
  17625. FreeParamValueList(o);
  17626. return 0;
  17627. }
  17628. // Register a new license key
  17629. UINT PsLicenseAdd(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17630. {
  17631. LIST *o;
  17632. PS *ps = (PS *)param;
  17633. UINT ret = 0;
  17634. RPC_TEST t;
  17635. // Parameter list that can be specified
  17636. PARAM args[] =
  17637. {
  17638. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  17639. {"[key]", CmdPrompt, _UU("CMD_LicenseAdd_Prompt_Key"), CmdEvalNotEmpty, NULL},
  17640. };
  17641. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  17642. if (o == NULL)
  17643. {
  17644. return ERR_INVALID_PARAMETER;
  17645. }
  17646. Zero(&t, sizeof(t));
  17647. StrCpy(t.StrValue, sizeof(t.StrValue), GetParamStr(o, "[key]"));
  17648. // RPC call
  17649. ret = ScAddLicenseKey(ps->Rpc, &t);
  17650. if (ret != ERR_NO_ERROR)
  17651. {
  17652. // An error has occured
  17653. CmdPrintError(c, ret);
  17654. FreeParamValueList(o);
  17655. return ret;
  17656. }
  17657. FreeParamValueList(o);
  17658. return 0;
  17659. }
  17660. // Delete the registered license
  17661. UINT PsLicenseDel(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17662. {
  17663. LIST *o;
  17664. PS *ps = (PS *)param;
  17665. UINT ret = 0;
  17666. RPC_TEST t;
  17667. // Parameter list that can be specified
  17668. PARAM args[] =
  17669. {
  17670. // "name", prompt_proc, prompt_param, eval_proc, eval_param
  17671. {"[id]", CmdPrompt, _UU("CMD_LicenseDel_Prompt_ID"), CmdEvalNotEmpty, NULL},
  17672. };
  17673. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  17674. if (o == NULL)
  17675. {
  17676. return ERR_INVALID_PARAMETER;
  17677. }
  17678. Zero(&t, sizeof(t));
  17679. t.IntValue = GetParamInt(o, "[id]");
  17680. // RPC call
  17681. ret = ScDelLicenseKey(ps->Rpc, &t);
  17682. if (ret != ERR_NO_ERROR)
  17683. {
  17684. // An error has occured
  17685. CmdPrintError(c, ret);
  17686. FreeParamValueList(o);
  17687. return ret;
  17688. }
  17689. FreeParamValueList(o);
  17690. return 0;
  17691. }
  17692. // Get the registered license list
  17693. UINT PsLicenseList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17694. {
  17695. LIST *o;
  17696. PS *ps = (PS *)param;
  17697. UINT ret = 0;
  17698. RPC_ENUM_LICENSE_KEY t;
  17699. CT *ct;
  17700. UINT i;
  17701. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  17702. if (o == NULL)
  17703. {
  17704. return ERR_INVALID_PARAMETER;
  17705. }
  17706. Zero(&t, sizeof(t));
  17707. // RPC call
  17708. ret = ScEnumLicenseKey(ps->Rpc, &t);
  17709. if (ret != ERR_NO_ERROR)
  17710. {
  17711. // An error has occured
  17712. CmdPrintError(c, ret);
  17713. FreeParamValueList(o);
  17714. return ret;
  17715. }
  17716. ct = CtNew();
  17717. CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_1"), false);
  17718. CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_2"), false);
  17719. CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_3"), false);
  17720. CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_4"), false);
  17721. CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_5"), false);
  17722. CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_6"), false);
  17723. CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_7"), false);
  17724. CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_8"), false);
  17725. CtInsertColumn(ct, _UU("SM_LICENSE_COLUMN_9"), false);
  17726. for (i = 0;i < t.NumItem;i++)
  17727. {
  17728. wchar_t tmp1[32], tmp2[LICENSE_KEYSTR_LEN + 1], tmp3[LICENSE_MAX_PRODUCT_NAME_LEN + 1],
  17729. *tmp4, tmp5[128], tmp6[LICENSE_LICENSEID_STR_LEN + 1], tmp7[64],
  17730. tmp8[64], tmp9[64];
  17731. RPC_ENUM_LICENSE_KEY_ITEM *e = &t.Items[i];
  17732. UniToStru(tmp1, e->Id);
  17733. StrToUni(tmp2, sizeof(tmp2), e->LicenseKey);
  17734. StrToUni(tmp3, sizeof(tmp3), e->LicenseName);
  17735. tmp4 = LiGetLicenseStatusStr(e->Status);
  17736. if (e->Expires == 0)
  17737. {
  17738. UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_LICENSE_NO_EXPIRES"));
  17739. }
  17740. else
  17741. {
  17742. GetDateStrEx64(tmp5, sizeof(tmp5), e->Expires, NULL);
  17743. }
  17744. StrToUni(tmp6, sizeof(tmp6), e->LicenseId);
  17745. UniToStru(tmp7, e->ProductId);
  17746. UniFormat(tmp8, sizeof(tmp8), L"%I64u", e->SystemId);
  17747. UniToStru(tmp9, e->SerialId);
  17748. CtInsert(ct,
  17749. tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9);
  17750. }
  17751. CtFreeEx(ct, c, true);
  17752. FreeRpcEnumLicenseKey(&t);
  17753. FreeParamValueList(o);
  17754. return 0;
  17755. }
  17756. // Get the license status of the current VPN Server
  17757. UINT PsLicenseStatus(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17758. {
  17759. LIST *o;
  17760. PS *ps = (PS *)param;
  17761. UINT ret = 0;
  17762. RPC_LICENSE_STATUS st;
  17763. CT *ct;
  17764. wchar_t tmp[MAX_SIZE];
  17765. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  17766. if (o == NULL)
  17767. {
  17768. return ERR_INVALID_PARAMETER;
  17769. }
  17770. Zero(&st, sizeof(st));
  17771. // RPC call
  17772. ret = ScGetLicenseStatus(ps->Rpc, &st);
  17773. if (ret != ERR_NO_ERROR)
  17774. {
  17775. // An error has occured
  17776. CmdPrintError(c, ret);
  17777. FreeParamValueList(o);
  17778. return ret;
  17779. }
  17780. ct = CtNewStandard();
  17781. if (st.EditionId == LICENSE_EDITION_VPN3_NO_LICENSE)
  17782. {
  17783. CtInsert(ct, _UU("SM_NO_LICENSE_COLUMN"), _UU("SM_NO_LICENSE"));
  17784. }
  17785. else
  17786. {
  17787. // Product edition name
  17788. StrToUni(tmp, sizeof(tmp), st.EditionStr);
  17789. CtInsert(ct, _UU("SM_LICENSE_STATUS_EDITION"), tmp);
  17790. // Release date
  17791. if (st.ReleaseDate != 0)
  17792. {
  17793. GetDateStrEx64(tmp, sizeof(tmp), st.ReleaseDate, NULL);
  17794. CtInsert(ct, _UU("SM_LICENSE_STATUS_RELEASE"), tmp);
  17795. }
  17796. // Current system ID
  17797. UniFormat(tmp, sizeof(tmp), L"%I64u", st.SystemId);
  17798. CtInsert(ct, _UU("SM_LICENSE_STATUS_SYSTEM_ID"), tmp);
  17799. // Expiration date of the current license product
  17800. if (st.SystemExpires == 0)
  17801. {
  17802. UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_NO_EXPIRES"));
  17803. }
  17804. else
  17805. {
  17806. GetDateStrEx64(tmp, sizeof(tmp), st.SystemExpires, NULL);
  17807. }
  17808. CtInsert(ct, _UU("SM_LICENSE_STATUS_EXPIRES"), tmp);
  17809. // Subscription (support) contract
  17810. if (st.NeedSubscription == false)
  17811. {
  17812. UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_STATUS_SUBSCRIPTION_NONEED"));
  17813. }
  17814. else
  17815. {
  17816. if (st.SubscriptionExpires == 0)
  17817. {
  17818. UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_STATUS_SUBSCRIPTION_NONE"));
  17819. }
  17820. else
  17821. {
  17822. wchar_t dtstr[MAX_PATH];
  17823. GetDateStrEx64(dtstr, sizeof(dtstr), st.SubscriptionExpires, NULL);
  17824. UniFormat(tmp, sizeof(tmp),
  17825. st.IsSubscriptionExpired ? _UU("SM_LICENSE_STATUS_SUBSCRIPTION_EXPIRED") : _UU("SM_LICENSE_STATUS_SUBSCRIPTION_VALID"),
  17826. dtstr);
  17827. }
  17828. }
  17829. CtInsert(ct, _UU("SM_LICENSE_STATUS_SUBSCRIPTION"), tmp);
  17830. if (st.NeedSubscription == false && st.SubscriptionExpires != 0)
  17831. {
  17832. wchar_t dtstr[MAX_PATH];
  17833. GetDateStrEx64(dtstr, sizeof(dtstr), st.SubscriptionExpires, NULL);
  17834. CtInsert(ct, _UU("SM_LICENSE_STATUS_SUBSCRIPTION_BUILD_STR"), tmp);
  17835. }
  17836. if (GetCapsBool(ps->CapsList, "b_vpn3"))
  17837. {
  17838. // Maximum creatable number of users
  17839. if (st.NumClientConnectLicense == INFINITE)
  17840. {
  17841. UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_INFINITE"));
  17842. }
  17843. else
  17844. {
  17845. UniToStru(tmp, st.NumClientConnectLicense);
  17846. }
  17847. CtInsert(ct, _UU("SM_LICENSE_NUM_CLIENT"), tmp);
  17848. }
  17849. // Available number of concurrent client connections
  17850. if (st.NumBridgeConnectLicense == INFINITE)
  17851. {
  17852. UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_INFINITE"));
  17853. }
  17854. else
  17855. {
  17856. UniToStru(tmp, st.NumBridgeConnectLicense);
  17857. }
  17858. CtInsert(ct, _UU("SM_LICENSE_NUM_BRIDGE"), tmp);
  17859. // Availability of enterprise features
  17860. CtInsert(ct, _UU("SM_LICENSE_STATUS_ENTERPRISE"),
  17861. st.AllowEnterpriseFunction ? _UU("SM_LICENSE_STATUS_ENTERPRISE_YES") : _UU("SM_LICENSE_STATUS_ENTERPRISE_NO"));
  17862. }
  17863. CtFreeEx(ct, c, false);
  17864. FreeParamValueList(o);
  17865. return 0;
  17866. }
  17867. // Get the cluster configuration
  17868. UINT PsClusterSettingGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17869. {
  17870. LIST *o;
  17871. PS *ps = (PS *)param;
  17872. UINT ret;
  17873. RPC_FARM t;
  17874. CT *ct;
  17875. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  17876. if (o == NULL)
  17877. {
  17878. return ERR_INVALID_PARAMETER;
  17879. }
  17880. Zero(&t, sizeof(t));
  17881. ret = ScGetFarmSetting(ps->Rpc, &t);
  17882. if (ret != ERR_NO_ERROR)
  17883. {
  17884. CmdPrintError(c, ret);
  17885. FreeParamValueList(o);
  17886. return ret;
  17887. }
  17888. if (t.Weight == 0)
  17889. {
  17890. t.Weight = FARM_DEFAULT_WEIGHT;
  17891. }
  17892. // Show the cluster configuration
  17893. ct = CtNewStandard();
  17894. CtInsert(ct, _UU("CMD_ClusterSettingGet_Current"),
  17895. GetServerTypeStr(t.ServerType));
  17896. if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)
  17897. {
  17898. CtInsert(ct, _UU("CMD_ClusterSettingGet_ControllerOnly"), t.ControllerOnly ? _UU("SEC_YES") : _UU("SEC_NO"));
  17899. }
  17900. if (t.ServerType != SERVER_TYPE_STANDALONE)
  17901. {
  17902. wchar_t tmp[MAX_SIZE];
  17903. UniToStru(tmp, t.Weight);
  17904. CtInsert(ct, _UU("CMD_ClusterSettingGet_Weight"), tmp);
  17905. }
  17906. if (t.ServerType == SERVER_TYPE_FARM_MEMBER)
  17907. {
  17908. wchar_t tmp[MAX_SIZE];
  17909. UINT i;
  17910. // Public IP address
  17911. if (t.PublicIp != 0)
  17912. {
  17913. IPToUniStr32(tmp, sizeof(tmp), t.PublicIp);
  17914. }
  17915. else
  17916. {
  17917. UniStrCpy(tmp, sizeof(tmp), _UU("CMD_ClusterSettingGet_None"));
  17918. }
  17919. CtInsert(ct, _UU("CMD_ClusterSettingGet_PublicIp"), tmp);
  17920. // Public port list
  17921. tmp[0] = 0;
  17922. for (i = 0;i < t.NumPort;i++)
  17923. {
  17924. wchar_t tmp2[64];
  17925. UniFormat(tmp2, sizeof(tmp2), L"%u, ", t.Ports[i]);
  17926. UniStrCat(tmp, sizeof(tmp), tmp2);
  17927. }
  17928. if (UniEndWith(tmp, L", "))
  17929. {
  17930. tmp[UniStrLen(tmp) - 2] = 0;
  17931. }
  17932. CtInsert(ct, _UU("CMD_ClusterSettingGet_PublicPorts"), tmp);
  17933. // Controller to connect
  17934. UniFormat(tmp, sizeof(tmp), L"%S:%u", t.ControllerName, t.ControllerPort);
  17935. CtInsert(ct, _UU("CMD_ClusterSettingGet_Controller"), tmp);
  17936. }
  17937. CtFree(ct, c);
  17938. FreeRpcFarm(&t);
  17939. FreeParamValueList(o);
  17940. return 0;
  17941. }
  17942. // Set the server password
  17943. UINT PsServerPasswordSet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  17944. {
  17945. LIST *o;
  17946. PS *ps = (PS *)param;
  17947. UINT ret;
  17948. RPC_SET_PASSWORD t;
  17949. char *pw;
  17950. PARAM args[] =
  17951. {
  17952. {"[password]", CmdPromptChoosePassword, NULL, NULL, NULL},
  17953. };
  17954. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  17955. if (o == NULL)
  17956. {
  17957. return ERR_INVALID_PARAMETER;
  17958. }
  17959. pw = GetParamStr(o, "[password]");
  17960. Zero(&t, sizeof(t));
  17961. Hash(t.HashedPassword, pw, StrLen(pw), true);
  17962. ret = ScSetServerPassword(ps->Rpc, &t);
  17963. if (ret != ERR_NO_ERROR)
  17964. {
  17965. CmdPrintError(c, ret);
  17966. FreeParamValueList(o);
  17967. return ret;
  17968. }
  17969. FreeParamValueList(o);
  17970. return 0;
  17971. }
  17972. // Password decision prompt (for Prompt function)
  17973. wchar_t *CmdPromptChoosePassword(CONSOLE *c, void *param)
  17974. {
  17975. char *s;
  17976. // Validate arguments
  17977. if (c == NULL)
  17978. {
  17979. return NULL;
  17980. }
  17981. s = CmdPasswordPrompt(c);
  17982. if (s == NULL)
  17983. {
  17984. return NULL;
  17985. }
  17986. else
  17987. {
  17988. wchar_t *ret = CopyStrToUni(s);
  17989. Free(s);
  17990. return ret;
  17991. }
  17992. }
  17993. // Password input prompt (general-purpose)
  17994. char *CmdPasswordPrompt(CONSOLE *c)
  17995. {
  17996. char *pw1, *pw2;
  17997. // Validate arguments
  17998. if (c == NULL)
  17999. {
  18000. return NULL;
  18001. }
  18002. c->Write(c, _UU("CMD_VPNCMD_PWPROMPT_0"));
  18003. RETRY:
  18004. c->Write(c, L"");
  18005. pw1 = c->ReadPassword(c, _UU("CMD_VPNCMD_PWPROMPT_1"));
  18006. if (pw1 == NULL)
  18007. {
  18008. return NULL;
  18009. }
  18010. pw2 = c->ReadPassword(c, _UU("CMD_VPNCMD_PWPROMPT_2"));
  18011. if (pw2 == NULL)
  18012. {
  18013. Free(pw1);
  18014. return NULL;
  18015. }
  18016. c->Write(c, L"");
  18017. if (StrCmp(pw1, pw2) != 0)
  18018. {
  18019. Free(pw1);
  18020. Free(pw2);
  18021. c->Write(c, _UU("CMD_VPNCMD_PWPROMPT_3"));
  18022. goto RETRY;
  18023. }
  18024. Free(pw1);
  18025. return pw2;
  18026. }
  18027. // Disable the listener
  18028. UINT PsListenerDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  18029. {
  18030. LIST *o;
  18031. PS *ps = (PS *)param;
  18032. UINT ret;
  18033. RPC_LISTENER t;
  18034. PARAM args[] =
  18035. {
  18036. {"[port]", CmdPromptPort, _UU("CMD_ListenerDisable_PortPrompt"), CmdEvalPort, NULL},
  18037. };
  18038. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  18039. if (o == NULL)
  18040. {
  18041. return ERR_INVALID_PARAMETER;
  18042. }
  18043. Zero(&t, sizeof(t));
  18044. t.Enable = false;
  18045. t.Port = ToInt(GetParamStr(o, "[port]"));
  18046. ret = ScEnableListener(ps->Rpc, &t);
  18047. if (ret != ERR_NO_ERROR)
  18048. {
  18049. CmdPrintError(c, ret);
  18050. FreeParamValueList(o);
  18051. return ret;
  18052. }
  18053. FreeParamValueList(o);
  18054. return 0;
  18055. }
  18056. // Enable the listener
  18057. UINT PsListenerEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  18058. {
  18059. LIST *o;
  18060. PS *ps = (PS *)param;
  18061. UINT ret;
  18062. RPC_LISTENER t;
  18063. PARAM args[] =
  18064. {
  18065. {"[port]", CmdPromptPort, _UU("CMD_ListenerEnable_PortPrompt"), CmdEvalPort, NULL},
  18066. };
  18067. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  18068. if (o == NULL)
  18069. {
  18070. return ERR_INVALID_PARAMETER;
  18071. }
  18072. Zero(&t, sizeof(t));
  18073. t.Enable = true;
  18074. t.Port = ToInt(GetParamStr(o, "[port]"));
  18075. ret = ScEnableListener(ps->Rpc, &t);
  18076. if (ret != ERR_NO_ERROR)
  18077. {
  18078. CmdPrintError(c, ret);
  18079. FreeParamValueList(o);
  18080. return ret;
  18081. }
  18082. FreeParamValueList(o);
  18083. return 0;
  18084. }
  18085. // Draw a row of console table
  18086. void CtPrintRow(CONSOLE *c, UINT num, UINT *widths, wchar_t **strings, bool *rights, char separate_char)
  18087. {
  18088. UINT i;
  18089. wchar_t *buf;
  18090. UINT buf_size;
  18091. bool is_sep_line = true;
  18092. // Validate arguments
  18093. if (c == NULL || num == 0 || widths == NULL || strings == NULL || rights == NULL)
  18094. {
  18095. return;
  18096. }
  18097. buf_size = 32;
  18098. for (i = 0;i < num;i++)
  18099. {
  18100. buf_size += sizeof(wchar_t) * widths[i] + 6;
  18101. }
  18102. buf = ZeroMalloc(buf_size);
  18103. for (i = 0;i < num;i++)
  18104. {
  18105. char *tmp;
  18106. wchar_t *space_string;
  18107. UINT w;
  18108. UINT space = 0;
  18109. wchar_t *string = strings[i];
  18110. wchar_t *tmp_line = NULL;
  18111. if (UniStrCmpi(string, L"---") == 0)
  18112. {
  18113. char *s = MakeCharArray('-', widths[i]);
  18114. tmp_line = string = CopyStrToUni(s);
  18115. Free(s);
  18116. }
  18117. else
  18118. {
  18119. is_sep_line = false;
  18120. }
  18121. w = UniStrWidth(string);
  18122. if (widths[i] >= w)
  18123. {
  18124. space = widths[i] - w;
  18125. }
  18126. tmp = MakeCharArray(' ', space);
  18127. space_string = CopyStrToUni(tmp);
  18128. if (rights[i] != false)
  18129. {
  18130. UniStrCat(buf, buf_size, space_string);
  18131. }
  18132. UniStrCat(buf, buf_size, string);
  18133. if (rights[i] == false)
  18134. {
  18135. UniStrCat(buf, buf_size, space_string);
  18136. }
  18137. Free(space_string);
  18138. Free(tmp);
  18139. if (i < (num - 1))
  18140. {
  18141. wchar_t tmp[4];
  18142. char str[2];
  18143. if (UniStrCmpi(strings[i], L"---") == 0)
  18144. {
  18145. str[0] = '+';
  18146. }
  18147. else
  18148. {
  18149. str[0] = separate_char;
  18150. }
  18151. str[1] = 0;
  18152. StrToUni(tmp, sizeof(tmp), str);
  18153. UniStrCat(buf, buf_size, tmp);
  18154. }
  18155. if (tmp_line != NULL)
  18156. {
  18157. Free(tmp_line);
  18158. }
  18159. }
  18160. UniTrimRight(buf);
  18161. if (is_sep_line)
  18162. {
  18163. if (UniStrLen(buf) > (c->GetWidth(c) - 1))
  18164. {
  18165. buf[c->GetWidth(c) - 1] = 0;
  18166. }
  18167. }
  18168. c->Write(c, buf);
  18169. Free(buf);
  18170. }
  18171. // Draw the console table in standard format
  18172. void CtPrintStandard(CT *ct, CONSOLE *c)
  18173. {
  18174. CT *t;
  18175. UINT i, j;
  18176. // Validate arguments
  18177. if (ct == NULL || c == NULL)
  18178. {
  18179. return;
  18180. }
  18181. t = CtNewStandard();
  18182. for (i = 0;i < LIST_NUM(ct->Rows);i++)
  18183. {
  18184. CTR *row = LIST_DATA(ct->Rows, i);
  18185. for (j = 0;j < LIST_NUM(ct->Columns);j++)
  18186. {
  18187. CTC *column = LIST_DATA(ct->Columns, j);
  18188. CtInsert(t, column->String, row->Strings[j]);
  18189. }
  18190. if (i != (LIST_NUM(ct->Rows) - 1))
  18191. {
  18192. CtInsert(t, L"---", L"---");
  18193. }
  18194. }
  18195. CtFree(t, c);
  18196. }
  18197. // Draw the console table
  18198. void CtPrint(CT *ct, CONSOLE *c)
  18199. {
  18200. UINT *widths;
  18201. UINT num;
  18202. UINT i, j;
  18203. wchar_t **header_strings;
  18204. bool *rights;
  18205. // Validate arguments
  18206. if (ct == NULL || c == NULL)
  18207. {
  18208. return;
  18209. }
  18210. num = LIST_NUM(ct->Columns);
  18211. widths = ZeroMalloc(sizeof(UINT) * num);
  18212. // Calculate the maximum character width of each column
  18213. for (i = 0;i < num;i++)
  18214. {
  18215. CTC *ctc = LIST_DATA(ct->Columns, i);
  18216. UINT w;
  18217. w = UniStrWidth(ctc->String);
  18218. widths[i] = MAX(widths[i], w);
  18219. }
  18220. for (j = 0;j < LIST_NUM(ct->Rows);j++)
  18221. {
  18222. CTR *ctr = LIST_DATA(ct->Rows, j);
  18223. for (i = 0;i < num;i++)
  18224. {
  18225. UINT w;
  18226. w = UniStrWidth(ctr->Strings[i]);
  18227. widths[i] = MAX(widths[i], w);
  18228. }
  18229. }
  18230. // Display the header part
  18231. header_strings = ZeroMalloc(sizeof(wchar_t *) * num);
  18232. rights = ZeroMalloc(sizeof(bool) * num);
  18233. for (i = 0;i < num;i++)
  18234. {
  18235. CTC *ctc = LIST_DATA(ct->Columns, i);
  18236. header_strings[i] = ctc->String;
  18237. rights[i] = ctc->Right;
  18238. }
  18239. CtPrintRow(c, num, widths, header_strings, rights, '|');
  18240. for (i = 0;i < num;i++)
  18241. {
  18242. char *s;
  18243. s = MakeCharArray('-', widths[i]);
  18244. header_strings[i] = CopyStrToUni(s);
  18245. Free(s);
  18246. }
  18247. CtPrintRow(c, num, widths, header_strings, rights, '+');
  18248. for (i = 0;i < num;i++)
  18249. {
  18250. Free(header_strings[i]);
  18251. }
  18252. // Display the data part
  18253. for (j = 0;j < LIST_NUM(ct->Rows);j++)
  18254. {
  18255. CTR *ctr = LIST_DATA(ct->Rows, j);
  18256. CtPrintRow(c, num, widths, ctr->Strings, rights, '|');
  18257. }
  18258. Free(rights);
  18259. Free(header_strings);
  18260. Free(widths);
  18261. }
  18262. // Escape the meta-characters in CSV
  18263. void CtEscapeCsv(wchar_t *dst, UINT size, wchar_t *src){
  18264. UINT i;
  18265. UINT len = UniStrLen(src);
  18266. UINT idx;
  18267. BOOL need_to_escape = false;
  18268. wchar_t tmp[2]=L"*";
  18269. // Check the input value
  18270. if (src==NULL || dst==NULL)
  18271. {
  18272. return;
  18273. }
  18274. // If there is no character that need to be escaped in the input characters, copy it to the output
  18275. len = UniStrLen(src);
  18276. for (i=0; i<len; i++)
  18277. {
  18278. tmp[0] = src[i];
  18279. if (tmp[0] == L","[0] || tmp[0] == L"\n"[0] || tmp[0] == L"\""[0])
  18280. {
  18281. need_to_escape = true;
  18282. }
  18283. }
  18284. if (need_to_escape == false)
  18285. {
  18286. UniStrCpy(dst,size,src);
  18287. return;
  18288. }
  18289. // If it contains meta characters (newline, comma, double quote), enclose with "
  18290. UniStrCpy(dst, size, L"\"");
  18291. idx = UniStrLen(dst);
  18292. if(idx<size-1)
  18293. {
  18294. for (i=0; i<len; i++)
  18295. {
  18296. tmp[0] = src[i];
  18297. // Convert " to "" in contents(MS-Excel method)
  18298. if (tmp[0] == L"\""[0])
  18299. {
  18300. UniStrCat(dst, size, tmp);
  18301. }
  18302. UniStrCat(dst, size, tmp);
  18303. }
  18304. }
  18305. UniStrCat(dst, size, L"\"");
  18306. return;
  18307. }
  18308. // Show a CSV format of console table
  18309. void CtPrintCsv(CT *ct, CONSOLE *c)
  18310. {
  18311. UINT i, j;
  18312. UINT num_columns = LIST_NUM(ct->Columns);
  18313. wchar_t buf[MAX_SIZE*4];
  18314. wchar_t fmtbuf[MAX_SIZE*4];
  18315. // Show the heading row
  18316. buf[0] = 0;
  18317. for(i=0; i<num_columns; i++)
  18318. {
  18319. CTC *ctc = LIST_DATA(ct->Columns, i);
  18320. CtEscapeCsv(fmtbuf, sizeof(fmtbuf), ctc->String);
  18321. UniStrCat(buf, sizeof(buf), fmtbuf);
  18322. if(i != num_columns-1)
  18323. UniStrCat(buf, sizeof(buf), L",");
  18324. }
  18325. c->Write(c, buf);
  18326. // Show the table body
  18327. for(j=0; j<LIST_NUM(ct->Rows); j++)
  18328. {
  18329. CTR *ctr = LIST_DATA(ct->Rows, j);
  18330. buf[0] = 0;
  18331. for(i=0; i<num_columns; i++)
  18332. {
  18333. CtEscapeCsv(fmtbuf, sizeof(fmtbuf), ctr->Strings[i]);
  18334. UniStrCat(buf, sizeof(buf), fmtbuf);
  18335. if(i != num_columns-1)
  18336. UniStrCat(buf, sizeof(buf), L",");
  18337. }
  18338. c->Write(c, buf);
  18339. }
  18340. }
  18341. // Delete the console table
  18342. void CtFreeEx(CT *ct, CONSOLE *c, bool standard_view)
  18343. {
  18344. UINT i, num;
  18345. // Validate arguments
  18346. if (ct == NULL)
  18347. {
  18348. return;
  18349. }
  18350. if (c != NULL)
  18351. {
  18352. if (c->ConsoleType == CONSOLE_CSV)
  18353. {
  18354. CtPrintCsv(ct, c);
  18355. }
  18356. else
  18357. {
  18358. if (standard_view == false)
  18359. {
  18360. CtPrint(ct, c);
  18361. }
  18362. else
  18363. {
  18364. CtPrintStandard(ct, c);
  18365. }
  18366. }
  18367. }
  18368. num = LIST_NUM(ct->Columns);
  18369. for (i = 0;i < LIST_NUM(ct->Rows);i++)
  18370. {
  18371. UINT j;
  18372. CTR *ctr = LIST_DATA(ct->Rows, i);
  18373. for (j = 0;j < num;j++)
  18374. {
  18375. Free(ctr->Strings[j]);
  18376. }
  18377. Free(ctr->Strings);
  18378. Free(ctr);
  18379. }
  18380. for (i = 0;i < LIST_NUM(ct->Columns);i++)
  18381. {
  18382. CTC *ctc = LIST_DATA(ct->Columns, i);
  18383. Free(ctc->String);
  18384. Free(ctc);
  18385. }
  18386. ReleaseList(ct->Columns);
  18387. ReleaseList(ct->Rows);
  18388. Free(ct);
  18389. }
  18390. void CtFree(CT *ct, CONSOLE *c)
  18391. {
  18392. CtFreeEx(ct, c, false);
  18393. }
  18394. // Add a row to the table
  18395. void CtInsert(CT *ct, ...)
  18396. {
  18397. CTR *ctr;
  18398. UINT num, i;
  18399. va_list va;
  18400. // Validate arguments
  18401. if (ct == NULL)
  18402. {
  18403. return;
  18404. }
  18405. num = LIST_NUM(ct->Columns);
  18406. va_start(va, ct);
  18407. ctr = ZeroMalloc(sizeof(CTR));
  18408. ctr->Strings = ZeroMalloc(sizeof(wchar_t *) * num);
  18409. for (i = 0;i < num;i++)
  18410. {
  18411. wchar_t *s = va_arg(va, wchar_t *);
  18412. ctr->Strings[i] = CopyUniStr(s);
  18413. }
  18414. va_end(va);
  18415. Insert(ct->Rows, ctr);
  18416. }
  18417. // Add a column to the table
  18418. void CtInsertColumn(CT *ct, wchar_t *str, bool right)
  18419. {
  18420. CTC *ctc;
  18421. // Validate arguments
  18422. if (ct == NULL)
  18423. {
  18424. return;
  18425. }
  18426. if (str == NULL)
  18427. {
  18428. str = L"";
  18429. }
  18430. ctc = ZeroMalloc(sizeof(CTC));
  18431. ctc->String = CopyUniStr(str);
  18432. ctc->Right = right;
  18433. Insert(ct->Columns, ctc);
  18434. }
  18435. // Create a new console table
  18436. CT *CtNew()
  18437. {
  18438. CT *ct;
  18439. ct = ZeroMalloc(sizeof(CT));
  18440. ct->Columns = NewList(NULL);
  18441. ct->Rows = NewList(NULL);
  18442. return ct;
  18443. }
  18444. // Add a standard column to a column in a table
  18445. CT *CtNewStandard()
  18446. {
  18447. CT *ct = CtNew();
  18448. CtInsertColumn(ct, _UU("CMD_CT_STD_COLUMN_1"), false);
  18449. CtInsertColumn(ct, _UU("CMD_CT_STD_COLUMN_2"), false);
  18450. return ct;
  18451. }
  18452. CT *CtNewStandardEx()
  18453. {
  18454. CT *ct = CtNew();
  18455. CtInsertColumn(ct, _UU("CMD_CT_STD_COLUMN_1"), false);
  18456. CtInsertColumn(ct, _UU("CMD_CT_STD_COLUMN_2"), false);
  18457. CtInsertColumn(ct, _UU("CMD_CT_STD_COLUMN_3"), false);
  18458. return ct;
  18459. }
  18460. // Get the TCP listener list
  18461. UINT PsListenerList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  18462. {
  18463. LIST *o;
  18464. PS *ps = (PS *)param;
  18465. UINT ret;
  18466. RPC_LISTENER_LIST t;
  18467. UINT i;
  18468. CT *ct;
  18469. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  18470. if (o == NULL)
  18471. {
  18472. return ERR_INVALID_PARAMETER;
  18473. }
  18474. Zero(&t, sizeof(t));
  18475. ret = ScEnumListener(ps->Rpc, &t);
  18476. if (ret != ERR_NO_ERROR)
  18477. {
  18478. CmdPrintError(c, ret);
  18479. FreeParamValueList(o);
  18480. return ret;
  18481. }
  18482. ct = CtNew();
  18483. CtInsertColumn(ct, _UU("CM_LISTENER_COLUMN_1"), false);
  18484. CtInsertColumn(ct, _UU("CM_LISTENER_COLUMN_2"), false);
  18485. for (i = 0;i < t.NumPort;i++)
  18486. {
  18487. wchar_t *status = _UU("CM_LISTENER_OFFLINE");
  18488. wchar_t tmp[128];
  18489. if (t.Errors[i])
  18490. {
  18491. status = _UU("CM_LISTENER_ERROR");
  18492. }
  18493. else if (t.Enables[i])
  18494. {
  18495. status = _UU("CM_LISTENER_ONLINE");
  18496. }
  18497. UniFormat(tmp, sizeof(tmp), _UU("CM_LISTENER_TCP_PORT"), t.Ports[i]);
  18498. CtInsert(ct, tmp, status);
  18499. }
  18500. CtFree(ct, c);
  18501. FreeRpcListenerList(&t);
  18502. FreeParamValueList(o);
  18503. return 0;
  18504. }
  18505. // Delete the TCP listener
  18506. UINT PsListenerDelete(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  18507. {
  18508. LIST *o;
  18509. PS *ps = (PS *)param;
  18510. UINT ret;
  18511. RPC_LISTENER t;
  18512. PARAM args[] =
  18513. {
  18514. {"[port]", CmdPromptPort, _UU("CMD_ListenerDelete_PortPrompt"), CmdEvalPort, NULL},
  18515. };
  18516. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  18517. if (o == NULL)
  18518. {
  18519. return ERR_INVALID_PARAMETER;
  18520. }
  18521. Zero(&t, sizeof(t));
  18522. t.Enable = true;
  18523. t.Port = ToInt(GetParamStr(o, "[port]"));
  18524. ret = ScDeleteListener(ps->Rpc, &t);
  18525. if (ret != ERR_NO_ERROR)
  18526. {
  18527. CmdPrintError(c, ret);
  18528. FreeParamValueList(o);
  18529. return ret;
  18530. }
  18531. FreeParamValueList(o);
  18532. return 0;
  18533. }
  18534. // Draw a row
  18535. void CmdPrintRow(CONSOLE *c, wchar_t *title, wchar_t *tag, ...)
  18536. {
  18537. wchar_t buf[MAX_SIZE * 2];
  18538. wchar_t buf2[MAX_SIZE * 2];
  18539. va_list args;
  18540. // Validate arguments
  18541. if (title == NULL || c == NULL || tag == NULL)
  18542. {
  18543. return;
  18544. }
  18545. va_start(args, tag);
  18546. UniFormatArgs(buf, sizeof(buf), tag, args);
  18547. UniFormat(buf2, sizeof(buf2), L"[%s] %s", title, buf);
  18548. va_end(args);
  18549. c->Write(c, buf2);
  18550. }
  18551. // ServerInfoGet command
  18552. UINT PsServerInfoGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  18553. {
  18554. LIST *o;
  18555. PS *ps = (PS *)param;
  18556. UINT ret;
  18557. RPC_SERVER_INFO t;
  18558. CT *ct;
  18559. wchar_t tmp[MAX_SIZE];
  18560. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  18561. if (o == NULL)
  18562. {
  18563. return ERR_INVALID_PARAMETER;
  18564. }
  18565. Zero(&t, sizeof(t));
  18566. ret = ScGetServerInfo(ps->Rpc, &t);
  18567. if (ret != ERR_NO_ERROR)
  18568. {
  18569. CmdPrintError(c, ret);
  18570. FreeParamValueList(o);
  18571. return ret;
  18572. }
  18573. ct = CtNew();
  18574. CtInsertColumn(ct, _UU("SM_STATUS_COLUMN_1"), false);
  18575. CtInsertColumn(ct, _UU("SM_STATUS_COLUMN_2"), false);
  18576. // Product name
  18577. StrToUni(tmp, sizeof(tmp), t.ServerProductName);
  18578. CtInsert(ct, _UU("SM_INFO_PRODUCT_NAME"), tmp);
  18579. // Version
  18580. StrToUni(tmp, sizeof(tmp), t.ServerVersionString);
  18581. CtInsert(ct, _UU("SM_INFO_VERSION"), tmp);
  18582. // Build
  18583. StrToUni(tmp, sizeof(tmp), t.ServerBuildInfoString);
  18584. CtInsert(ct, _UU("SM_INFO_BUILD"), tmp);
  18585. // Host name
  18586. StrToUni(tmp, sizeof(tmp), t.ServerHostName);
  18587. CtInsert(ct, _UU("SM_INFO_HOSTNAME"), tmp);
  18588. // Type
  18589. CtInsert(ct, _UU("SM_ST_SERVER_TYPE"), GetServerTypeStr(t.ServerType));
  18590. // OS
  18591. StrToUni(tmp, sizeof(tmp), t.OsInfo.OsSystemName);
  18592. CtInsert(ct, _UU("SM_OS_SYSTEM_NAME"), tmp);
  18593. StrToUni(tmp, sizeof(tmp), t.OsInfo.OsProductName);
  18594. CtInsert(ct, _UU("SM_OS_PRODUCT_NAME"), tmp);
  18595. if (t.OsInfo.OsServicePack != 0)
  18596. {
  18597. UniFormat(tmp, sizeof(tmp), _UU("SM_OS_SP_TAG"), t.OsInfo.OsServicePack);
  18598. CtInsert(ct, _UU("SM_OS_SERVICE_PACK"), tmp);
  18599. }
  18600. StrToUni(tmp, sizeof(tmp), t.OsInfo.OsVendorName);
  18601. CtInsert(ct, _UU("SM_OS_VENDER_NAME"), tmp);
  18602. StrToUni(tmp, sizeof(tmp), t.OsInfo.OsVersion);
  18603. CtInsert(ct, _UU("SM_OS_VERSION"), tmp);
  18604. StrToUni(tmp, sizeof(tmp), t.OsInfo.KernelName);
  18605. CtInsert(ct, _UU("SM_OS_KERNEL_NAME"), tmp);
  18606. StrToUni(tmp, sizeof(tmp), t.OsInfo.KernelVersion);
  18607. CtInsert(ct, _UU("SM_OS_KERNEL_VERSION"), tmp);
  18608. CtFree(ct, c);
  18609. FreeRpcServerInfo(&t);
  18610. FreeParamValueList(o);
  18611. return 0;
  18612. }
  18613. // Get the string for type of the HUB
  18614. wchar_t *GetHubTypeStr(UINT type)
  18615. {
  18616. if (type == HUB_TYPE_FARM_STATIC)
  18617. {
  18618. return _UU("SM_HUB_STATIC");
  18619. }
  18620. else if (type == HUB_TYPE_FARM_DYNAMIC)
  18621. {
  18622. return _UU("SM_HUB_DYNAMIC");
  18623. }
  18624. return _UU("SM_HUB_STANDALONE");
  18625. }
  18626. // Get a string of the type of server
  18627. wchar_t *GetServerTypeStr(UINT type)
  18628. {
  18629. if (type == SERVER_TYPE_FARM_CONTROLLER)
  18630. {
  18631. return _UU("SM_FARM_CONTROLLER");
  18632. }
  18633. else if (type == SERVER_TYPE_FARM_MEMBER)
  18634. {
  18635. return _UU("SM_FARM_MEMBER");
  18636. }
  18637. return _UU("SM_SERVER_STANDALONE");
  18638. }
  18639. // ServerStatusGet command
  18640. UINT PsServerStatusGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  18641. {
  18642. LIST *o;
  18643. PS *ps = (PS *)param;
  18644. UINT ret;
  18645. RPC_SERVER_STATUS t;
  18646. wchar_t tmp[MAX_PATH];
  18647. char tmp2[MAX_PATH];
  18648. CT *ct;
  18649. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  18650. if (o == NULL)
  18651. {
  18652. return ERR_INVALID_PARAMETER;
  18653. }
  18654. Zero(&t, sizeof(t));
  18655. ret = ScGetServerStatus(ps->Rpc, &t);
  18656. if (ret != ERR_NO_ERROR)
  18657. {
  18658. CmdPrintError(c, ret);
  18659. FreeParamValueList(o);
  18660. return ret;
  18661. }
  18662. ct = CtNew();
  18663. CtInsertColumn(ct, _UU("SM_STATUS_COLUMN_1"), false);
  18664. CtInsertColumn(ct, _UU("SM_STATUS_COLUMN_2"), false);
  18665. // Type of server
  18666. CtInsert(ct, _UU("SM_ST_SERVER_TYPE"),
  18667. t.ServerType == SERVER_TYPE_STANDALONE ? _UU("SM_SERVER_STANDALONE") :
  18668. t.ServerType == SERVER_TYPE_FARM_MEMBER ? _UU("SM_FARM_MEMBER") : _UU("SM_FARM_CONTROLLER"));
  18669. // Number of TCP connections
  18670. UniToStru(tmp, t.NumTcpConnections);
  18671. CtInsert(ct, _UU("SM_ST_NUM_TCP"), tmp);
  18672. if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)
  18673. {
  18674. // Number of local TCP connections
  18675. UniToStru(tmp, t.NumTcpConnectionsLocal);
  18676. CtInsert(ct, _UU("SM_ST_NUM_TCP_LOCAL"), tmp);
  18677. // Number of remote TCP connections
  18678. UniToStru(tmp, t.NumTcpConnectionsRemote);
  18679. CtInsert(ct, _UU("SM_ST_NUM_TCP_REMOTE"), tmp);
  18680. }
  18681. // Number of Virtual HUBs
  18682. UniToStru(tmp, t.NumHubTotal);
  18683. CtInsert(ct, _UU("SM_ST_NUM_HUB_TOTAL"), tmp);
  18684. if (t.ServerType != SERVER_TYPE_STANDALONE)
  18685. {
  18686. // Number of static HUBs
  18687. UniToStru(tmp, t.NumHubStatic);
  18688. CtInsert(ct, _UU("SM_ST_NUM_HUB_STATIC"), tmp);
  18689. // Number of dynamic HUBs
  18690. UniToStru(tmp, t.NumHubDynamic);
  18691. CtInsert(ct, _UU("SM_ST_NUM_HUB_DYNAMIC"), tmp);
  18692. }
  18693. // Number of sessions
  18694. UniToStru(tmp, t.NumSessionsTotal);
  18695. CtInsert(ct, _UU("SM_ST_NUM_SESSION_TOTAL"), tmp);
  18696. if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)
  18697. {
  18698. // Number of local sessions
  18699. UniToStru(tmp, t.NumSessionsLocal);
  18700. CtInsert(ct, _UU("SM_ST_NUM_SESSION_LOCAL"), tmp);
  18701. // Number of remote sessions
  18702. UniToStru(tmp, t.NumSessionsRemote);
  18703. CtInsert(ct, _UU("SM_ST_NUM_SESSION_REMOTE"), tmp);
  18704. }
  18705. // Number of MAC tables
  18706. UniToStru(tmp, t.NumMacTables);
  18707. CtInsert(ct, _UU("SM_ST_NUM_MAC_TABLE"), tmp);
  18708. // Number of IP tables
  18709. UniToStru(tmp, t.NumIpTables);
  18710. CtInsert(ct, _UU("SM_ST_NUM_IP_TABLE"), tmp);
  18711. // Number of users
  18712. UniToStru(tmp, t.NumUsers);
  18713. CtInsert(ct, _UU("SM_ST_NUM_USERS"), tmp);
  18714. // Number of groups
  18715. UniToStru(tmp, t.NumGroups);
  18716. CtInsert(ct, _UU("SM_ST_NUM_GROUPS"), tmp);
  18717. // Number of assigned licenses
  18718. UniToStru(tmp, t.AssignedClientLicenses);
  18719. CtInsert(ct, _UU("SM_ST_CLIENT_LICENSE"), tmp);
  18720. UniToStru(tmp, t.AssignedBridgeLicenses);
  18721. CtInsert(ct, _UU("SM_ST_BRIDGE_LICENSE"), tmp);
  18722. if (t.ServerType == SERVER_TYPE_FARM_CONTROLLER)
  18723. {
  18724. UniToStru(tmp, t.AssignedClientLicensesTotal);
  18725. CtInsert(ct, _UU("SM_ST_CLIENT_LICENSE_EX"), tmp);
  18726. UniToStru(tmp, t.AssignedBridgeLicensesTotal);
  18727. CtInsert(ct, _UU("SM_ST_BRIDGE_LICENSE_EX"), tmp);
  18728. }
  18729. // Traffic
  18730. CmdInsertTrafficInfo(ct, &t.Traffic);
  18731. // Server start-up time
  18732. GetDateTimeStrEx64(tmp, sizeof(tmp), SystemToLocal64(t.StartTime), NULL);
  18733. CtInsert(ct, _UU("SM_ST_START_TIME"), tmp);
  18734. // Current time
  18735. GetDateTimeStrMilli64(tmp2, sizeof(tmp2), SystemToLocal64(t.CurrentTime));
  18736. StrToUni(tmp, sizeof(tmp), tmp2);
  18737. CtInsert(ct, _UU("SM_ST_CURRENT_TIME"), tmp);
  18738. // Tick value
  18739. UniFormat(tmp, sizeof(tmp), L"%I64u", t.CurrentTick);
  18740. CtInsert(ct, _UU("SM_ST_CURRENT_TICK"), tmp);
  18741. // Memory information
  18742. if (t.MemInfo.TotalMemory != 0)
  18743. {
  18744. char vv[128];
  18745. ToStr3(vv, sizeof(vv), t.MemInfo.TotalMemory);
  18746. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);
  18747. CtInsert(ct, _UU("SM_ST_TOTAL_MEMORY"), tmp);
  18748. ToStr3(vv, sizeof(vv), t.MemInfo.UsedMemory);
  18749. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);
  18750. CtInsert(ct, _UU("SM_ST_USED_MEMORY"), tmp);
  18751. ToStr3(vv, sizeof(vv), t.MemInfo.FreeMemory);
  18752. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);
  18753. CtInsert(ct, _UU("SM_ST_FREE_MEMORY"), tmp);
  18754. ToStr3(vv, sizeof(vv), t.MemInfo.TotalPhys);
  18755. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);
  18756. CtInsert(ct, _UU("SM_ST_TOTAL_PHYS"), tmp);
  18757. ToStr3(vv, sizeof(vv), t.MemInfo.UsedPhys);
  18758. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);
  18759. CtInsert(ct, _UU("SM_ST_USED_PHYS"), tmp);
  18760. ToStr3(vv, sizeof(vv), t.MemInfo.FreePhys);
  18761. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_RAM_SIZE_KB"), vv);
  18762. CtInsert(ct, _UU("SM_ST_FREE_PHYS"), tmp);
  18763. }
  18764. CtFree(ct, c);
  18765. FreeParamValueList(o);
  18766. return 0;
  18767. }
  18768. // Add traffic information to LVB
  18769. void CmdInsertTrafficInfo(CT *ct, TRAFFIC *t)
  18770. {
  18771. wchar_t tmp[MAX_SIZE];
  18772. char vv[128];
  18773. // Validate arguments
  18774. if (ct == NULL || t == NULL)
  18775. {
  18776. return;
  18777. }
  18778. // Transmission information
  18779. ToStr3(vv, sizeof(vv), t->Send.UnicastCount);
  18780. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_NUM_PACKET_STR"), vv);
  18781. CtInsert(ct, _UU("SM_ST_SEND_UCAST_NUM"), tmp);
  18782. ToStr3(vv, sizeof(vv), t->Send.UnicastBytes);
  18783. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_SIZE_BYTE_STR"), vv);
  18784. CtInsert(ct, _UU("SM_ST_SEND_UCAST_SIZE"), tmp);
  18785. ToStr3(vv, sizeof(vv), t->Send.BroadcastCount);
  18786. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_NUM_PACKET_STR"), vv);
  18787. CtInsert(ct, _UU("SM_ST_SEND_BCAST_NUM"), tmp);
  18788. ToStr3(vv, sizeof(vv), t->Send.BroadcastBytes);
  18789. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_SIZE_BYTE_STR"), vv);
  18790. CtInsert(ct, _UU("SM_ST_SEND_BCAST_SIZE"), tmp);
  18791. // Reception information
  18792. ToStr3(vv, sizeof(vv), t->Recv.UnicastCount);
  18793. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_NUM_PACKET_STR"), vv);
  18794. CtInsert(ct, _UU("SM_ST_RECV_UCAST_NUM"), tmp);
  18795. ToStr3(vv, sizeof(vv), t->Recv.UnicastBytes);
  18796. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_SIZE_BYTE_STR"), vv);
  18797. CtInsert(ct, _UU("SM_ST_RECV_UCAST_SIZE"), tmp);
  18798. ToStr3(vv, sizeof(vv), t->Recv.BroadcastCount);
  18799. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_NUM_PACKET_STR"), vv);
  18800. CtInsert(ct, _UU("SM_ST_RECV_BCAST_NUM"), tmp);
  18801. ToStr3(vv, sizeof(vv), t->Recv.BroadcastBytes);
  18802. UniFormat(tmp, sizeof(tmp), _UU("SM_ST_SIZE_BYTE_STR"), vv);
  18803. CtInsert(ct, _UU("SM_ST_RECV_BCAST_SIZE"), tmp);
  18804. }
  18805. // Input a port number
  18806. wchar_t *CmdPromptPort(CONSOLE *c, void *param)
  18807. {
  18808. wchar_t *prompt_str;
  18809. if (param != NULL)
  18810. {
  18811. prompt_str = (wchar_t *)param;
  18812. }
  18813. else
  18814. {
  18815. prompt_str = _UU("CMD_PROPMT_PORT");
  18816. }
  18817. return c->ReadLine(c, prompt_str, true);
  18818. }
  18819. // Verify the port number
  18820. bool CmdEvalPort(CONSOLE *c, wchar_t *str, void *param)
  18821. {
  18822. UINT i;
  18823. // Validate arguments
  18824. if (c == NULL || str == NULL)
  18825. {
  18826. return false;
  18827. }
  18828. i = UniToInt(str);
  18829. if (i >= 1 && i <= 65535)
  18830. {
  18831. return true;
  18832. }
  18833. c->Write(c, _UU("CMD_EVAL_PORT"));
  18834. return false;
  18835. }
  18836. // ListenerCreate command
  18837. UINT PsListenerCreate(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  18838. {
  18839. LIST *o;
  18840. PS *ps = (PS *)param;
  18841. UINT ret;
  18842. RPC_LISTENER t;
  18843. PARAM args[] =
  18844. {
  18845. {"[port]", CmdPromptPort, _UU("CMD_ListenerCreate_PortPrompt"), CmdEvalPort, NULL},
  18846. };
  18847. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  18848. if (o == NULL)
  18849. {
  18850. return ERR_INVALID_PARAMETER;
  18851. }
  18852. Zero(&t, sizeof(t));
  18853. t.Enable = true;
  18854. t.Port = ToInt(GetParamStr(o, "[port]"));
  18855. ret = ScCreateListener(ps->Rpc, &t);
  18856. if (ret != ERR_NO_ERROR)
  18857. {
  18858. CmdPrintError(c, ret);
  18859. FreeParamValueList(o);
  18860. return ret;
  18861. }
  18862. FreeParamValueList(o);
  18863. return 0;
  18864. }
  18865. // About command
  18866. UINT PsAbout(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  18867. {
  18868. LIST *o;
  18869. BUF *b;
  18870. o = ParseCommandList(c, cmd_name, str, NULL, 0);
  18871. if (o == NULL)
  18872. {
  18873. return ERR_INVALID_PARAMETER;
  18874. }
  18875. b = ReadDump("|legal.txt");
  18876. CmdPrintAbout(c);
  18877. c->Write(c, L"\r\n");
  18878. if (b != NULL)
  18879. {
  18880. wchar_t *s;
  18881. SeekBufToEnd(b);
  18882. WriteBufChar(b, 13);
  18883. WriteBufChar(b, 10);
  18884. WriteBufChar(b, 0);
  18885. s = CopyUtfToUni(b->Buf);
  18886. c->Write(c, s);
  18887. Free(s);
  18888. }
  18889. // Display the version information
  18890. c->Write(c, _UU("D_ABOUT@S_INFO3"));
  18891. c->Write(c, L"\r\n");
  18892. c->Write(c, _UU("D_ABOUT@S_INFO4"));
  18893. c->Write(c, L"\r\n");
  18894. CmdPrintAbout(c);
  18895. c->Write(c, L"\r\n");
  18896. FreeParamValueList(o);
  18897. FreeBuf(b);
  18898. return 0;
  18899. }
  18900. // Creat a new server management context
  18901. PS *NewPs(CONSOLE *c, RPC *rpc, char *servername, UINT serverport, char *hubname, char *adminhub, wchar_t *cmdline)
  18902. {
  18903. PS *ps;
  18904. // Validate arguments
  18905. if (c == NULL || rpc == NULL || servername == NULL)
  18906. {
  18907. return NULL;
  18908. }
  18909. if (IsEmptyStr(hubname))
  18910. {
  18911. hubname = NULL;
  18912. }
  18913. if (IsEmptyStr(adminhub))
  18914. {
  18915. adminhub = NULL;
  18916. }
  18917. if (UniIsEmptyStr(cmdline))
  18918. {
  18919. cmdline = NULL;
  18920. }
  18921. ps = ZeroMalloc(sizeof(PS));
  18922. ps->ConsoleForServer = true;
  18923. ps->ServerPort = serverport;
  18924. ps->ServerName = CopyStr(servername);
  18925. ps->Console = c;
  18926. ps->Rpc = rpc;
  18927. ps->HubName = CopyStr(hubname);
  18928. ps->LastError = 0;
  18929. ps->AdminHub = CopyStr(adminhub);
  18930. ps->CmdLine = CopyUniStr(cmdline);
  18931. return ps;
  18932. }
  18933. // Release the server management context
  18934. void FreePs(PS *ps)
  18935. {
  18936. // Validate arguments
  18937. if (ps == NULL)
  18938. {
  18939. return;
  18940. }
  18941. Free(ps->HubName);
  18942. Free(ps->AdminHub);
  18943. Free(ps->CmdLine);
  18944. Free(ps->ServerName);
  18945. Free(ps);
  18946. }
  18947. // Server Administration Tool
  18948. UINT PsConnect(CONSOLE *c, char *host, UINT port, char *hub, char *adminhub, wchar_t *cmdline, char *password)
  18949. {
  18950. UINT retcode = 0;
  18951. RPC *rpc = NULL;
  18952. CEDAR *cedar;
  18953. CLIENT_OPTION o;
  18954. UCHAR hashed_password[SHA1_SIZE];
  18955. bool b = false;
  18956. // Validate arguments
  18957. if (c == NULL || host == NULL)
  18958. {
  18959. return ERR_INVALID_PARAMETER;
  18960. }
  18961. if (port == 0)
  18962. {
  18963. port = 443;
  18964. }
  18965. if (hub != NULL)
  18966. {
  18967. adminhub = NULL;
  18968. }
  18969. cedar = NewCedar(NULL, NULL);
  18970. Zero(&o, sizeof(o));
  18971. UniStrCpy(o.AccountName, sizeof(o.AccountName), L"VPNCMD");
  18972. StrCpy(o.Hostname, sizeof(o.Hostname), host);
  18973. o.Port = port;
  18974. o.ProxyType = PROXY_DIRECT;
  18975. Hash(hashed_password, password, StrLen(password), true);
  18976. if (IsEmptyStr(password) == false)
  18977. {
  18978. b = true;
  18979. }
  18980. // Connect
  18981. while (true)
  18982. {
  18983. UINT err;
  18984. rpc = AdminConnectEx(cedar, &o, hub, hashed_password, &err, CEDAR_CUI_STR);
  18985. if (rpc == NULL)
  18986. {
  18987. // Failure
  18988. retcode = err;
  18989. if (err == ERR_ACCESS_DENIED && c->ProgrammingMode == false)
  18990. {
  18991. char *pass;
  18992. // Password is incorrect
  18993. if (b)
  18994. {
  18995. // Input the password
  18996. c->Write(c, _UU("CMD_VPNCMD_PASSWORD_1"));
  18997. }
  18998. b = true;
  18999. pass = c->ReadPassword(c, _UU("CMD_VPNCMD_PASSWORD_2"));
  19000. c->Write(c, L"");
  19001. if (pass != NULL)
  19002. {
  19003. Hash(hashed_password, pass, StrLen(pass), true);
  19004. Free(pass);
  19005. }
  19006. else
  19007. {
  19008. break;
  19009. }
  19010. }
  19011. else
  19012. {
  19013. // Other errors
  19014. CmdPrintError(c, err);
  19015. break;
  19016. }
  19017. }
  19018. else
  19019. {
  19020. PS *ps;
  19021. // Success
  19022. ps = NewPs(c, rpc, host, port, hub, adminhub, cmdline);
  19023. PsMain(ps);
  19024. retcode = ps->LastError;
  19025. FreePs(ps);
  19026. AdminDisconnect(rpc);
  19027. break;
  19028. }
  19029. }
  19030. ReleaseCedar(cedar);
  19031. return retcode;
  19032. }
  19033. // Display the error
  19034. void CmdPrintError(CONSOLE *c, UINT err)
  19035. {
  19036. wchar_t tmp[MAX_SIZE];
  19037. // Validate arguments
  19038. if (c == NULL)
  19039. {
  19040. return;
  19041. }
  19042. UniFormat(tmp, sizeof(tmp), _UU("CMD_VPNCMD_ERROR"),
  19043. err, GetUniErrorStr(err));
  19044. c->Write(c, tmp);
  19045. if (err == ERR_DISCONNECTED)
  19046. {
  19047. c->Write(c, _UU("CMD_DISCONNECTED_MSG"));
  19048. }
  19049. }
  19050. // Display the version information
  19051. void CmdPrintAbout(CONSOLE *c)
  19052. {
  19053. CEDAR *cedar;
  19054. wchar_t tmp[MAX_SIZE];
  19055. char exe[MAX_PATH];
  19056. // Validate arguments
  19057. if (c == NULL)
  19058. {
  19059. return;
  19060. }
  19061. cedar = NewCedar(NULL, NULL);
  19062. GetExeName(exe, sizeof(exe));
  19063. UniFormat(tmp, sizeof(tmp), _UU("CMD_VPNCMD_ABOUT"),
  19064. cedar->VerString, cedar->BuildInfo);
  19065. c->Write(c, tmp);
  19066. ReleaseCedar(cedar);
  19067. }
  19068. // Parse the host name and port number (Separated by @)
  19069. bool ParseHostPortAtmark(char *src, char **host, UINT *port, UINT default_port)
  19070. {
  19071. TOKEN_LIST *t;
  19072. bool ret = false;
  19073. // Validate arguments
  19074. if (src == NULL)
  19075. {
  19076. return false;
  19077. }
  19078. t = ParseToken(src, "@");
  19079. if (t == NULL)
  19080. {
  19081. return false;
  19082. }
  19083. if (port != NULL)
  19084. {
  19085. *port = 0;
  19086. }
  19087. if (default_port == 0)
  19088. {
  19089. if (t->NumTokens < 2)
  19090. {
  19091. FreeToken(t);
  19092. return false;
  19093. }
  19094. if (ToInt(t->Token[1]) == 0)
  19095. {
  19096. FreeToken(t);
  19097. return false;
  19098. }
  19099. }
  19100. if (t->NumTokens >= 2 && ToInt(t->Token[1]) == 0)
  19101. {
  19102. FreeToken(t);
  19103. return false;
  19104. }
  19105. if (t->NumTokens >= 1 && IsEmptyStr(t->Token[0]) == false)
  19106. {
  19107. ret = true;
  19108. if (host != NULL)
  19109. {
  19110. *host = CopyStr(t->Token[0]);
  19111. Trim(*host);
  19112. }
  19113. if (t->NumTokens >= 2)
  19114. {
  19115. if (port != NULL)
  19116. {
  19117. *port = ToInt(t->Token[1]);
  19118. }
  19119. }
  19120. }
  19121. if (port != NULL)
  19122. {
  19123. if (*port == 0)
  19124. {
  19125. *port = default_port;
  19126. }
  19127. }
  19128. FreeToken(t);
  19129. return ret;
  19130. }
  19131. // Parse the host name and port number
  19132. bool ParseHostPort(char *src, char **host, UINT *port, UINT default_port)
  19133. {
  19134. TOKEN_LIST *t;
  19135. bool ret = false;
  19136. // Validate arguments
  19137. if (src == NULL)
  19138. {
  19139. return false;
  19140. }
  19141. if (StartWith(src, "["))
  19142. {
  19143. if (InStr(src, "]"))
  19144. {
  19145. // Format of [target]:port
  19146. UINT i, n;
  19147. char tmp[MAX_SIZE];
  19148. StrCpy(tmp, sizeof(tmp), src);
  19149. n = SearchStrEx(tmp, "]", 0, false);
  19150. if (n != INFINITE)
  19151. {
  19152. UINT len = StrLen(tmp);
  19153. for (i = n;i < len;i++)
  19154. {
  19155. if (tmp[i] == ':')
  19156. {
  19157. tmp[i] = '@';
  19158. }
  19159. }
  19160. }
  19161. return ParseHostPortAtmark(tmp, host, port, default_port);
  19162. }
  19163. }
  19164. if (InStr(src, "@"))
  19165. {
  19166. // It is separated by @
  19167. return ParseHostPortAtmark(src, host, port, default_port);
  19168. }
  19169. t = ParseToken(src, ":");
  19170. if (t == NULL)
  19171. {
  19172. return false;
  19173. }
  19174. if (port != NULL)
  19175. {
  19176. *port = 0;
  19177. }
  19178. if (default_port == 0)
  19179. {
  19180. if (t->NumTokens < 2)
  19181. {
  19182. FreeToken(t);
  19183. return false;
  19184. }
  19185. if (ToInt(t->Token[1]) == 0)
  19186. {
  19187. FreeToken(t);
  19188. return false;
  19189. }
  19190. }
  19191. if (t->NumTokens >= 2 && ToInt(t->Token[1]) == 0)
  19192. {
  19193. FreeToken(t);
  19194. return false;
  19195. }
  19196. if (t->NumTokens >= 1 && IsEmptyStr(t->Token[0]) == false)
  19197. {
  19198. ret = true;
  19199. if (host != NULL)
  19200. {
  19201. *host = CopyStr(t->Token[0]);
  19202. Trim(*host);
  19203. }
  19204. if (t->NumTokens >= 2)
  19205. {
  19206. if (port != NULL)
  19207. {
  19208. *port = ToInt(t->Token[1]);
  19209. }
  19210. }
  19211. }
  19212. if (port != NULL)
  19213. {
  19214. if (*port == 0)
  19215. {
  19216. *port = default_port;
  19217. }
  19218. }
  19219. FreeToken(t);
  19220. return ret;
  19221. }
  19222. // Vpncmd command procedure
  19223. UINT VpnCmdProc(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
  19224. {
  19225. LIST *o;
  19226. char *target;
  19227. bool server = false;
  19228. bool client = false;
  19229. bool tools = false;
  19230. char *hostname = NULL;
  19231. char *password;
  19232. wchar_t *cmdline;
  19233. bool host_inputted = false;
  19234. UINT port = 0;
  19235. UINT retcode = 0;
  19236. PARAM args[] =
  19237. {
  19238. {"[host:port]", NULL, NULL, NULL, NULL},
  19239. {"CLIENT", NULL, NULL, NULL, NULL},
  19240. {"SERVER", NULL, NULL, NULL, NULL},
  19241. {"TOOLS", NULL, NULL, NULL, NULL},
  19242. {"HUB", NULL, NULL, NULL, NULL},
  19243. {"ADMINHUB", NULL, NULL, NULL, NULL},
  19244. {"PASSWORD", NULL, NULL, NULL, NULL},
  19245. {"IN", NULL, NULL, NULL, NULL},
  19246. {"OUT", NULL, NULL, NULL, NULL},
  19247. {"CMD", NULL, NULL, NULL, NULL},
  19248. {"CSV", NULL, NULL, NULL, NULL},
  19249. {"PROGRAMMING", NULL, NULL, NULL, NULL},
  19250. };
  19251. #ifdef OS_WIN32
  19252. if (UniStrCmpi(str, L"/debug") == 0)
  19253. {
  19254. // Debug information write mode
  19255. Win32CmdDebug(false);
  19256. return 0;
  19257. }
  19258. if (UniStrCmpi(str, L"/debug_uac") == 0)
  19259. {
  19260. // Debug information write mode
  19261. Win32CmdDebug(true);
  19262. return 0;
  19263. }
  19264. #endif // OS_WIN32
  19265. if (c->ConsoleType == CONSOLE_LOCAL)
  19266. {
  19267. // Initialize the execute path information
  19268. VpnCmdInitBootPath();
  19269. }
  19270. if(c->ConsoleType != CONSOLE_CSV)
  19271. {
  19272. CmdPrintAbout(c);
  19273. c->Write(c, L"");
  19274. }
  19275. o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
  19276. if (o == NULL)
  19277. {
  19278. return ERR_INVALID_PARAMETER;
  19279. }
  19280. // Specification of the mode of Tools or Server or Client
  19281. if ((GetParamStr(o, "CLIENT") == NULL && GetParamStr(o, "SERVER") == NULL && GetParamStr(o, "TOOLS") == NULL) ||
  19282. (GetParamStr(o, "CLIENT") != NULL && GetParamStr(o, "SERVER") != NULL && GetParamStr(o, "TOOLS") != NULL))
  19283. {
  19284. wchar_t *ret;
  19285. UINT code;
  19286. // The mode of Tools or Server or Client is not specified
  19287. c->Write(c, _UU("CMD_VPNCMD_CS_1"));
  19288. ret = c->ReadLine(c, _UU("CMD_VPNCMD_CS_2"), true);
  19289. code = UniToInt(ret);
  19290. Free(ret);
  19291. switch (code)
  19292. {
  19293. case 1:
  19294. // Server
  19295. server = true;
  19296. break;
  19297. case 2:
  19298. // Client
  19299. client = true;
  19300. break;
  19301. case 3:
  19302. // Tools
  19303. tools = true;
  19304. break;
  19305. default:
  19306. // Unspecified
  19307. FreeParamValueList(o);
  19308. return ERR_USER_CANCEL;
  19309. }
  19310. c->Write(c, L"");
  19311. }
  19312. else
  19313. {
  19314. if (GetParamStr(o, "SERVER") != NULL)
  19315. {
  19316. server = true;
  19317. }
  19318. else if (GetParamStr(o, "CLIENT") != NULL)
  19319. {
  19320. client = true;
  19321. }
  19322. else
  19323. {
  19324. tools = true;
  19325. }
  19326. }
  19327. // Destination host name
  19328. target = CopyStr(GetParamStr(o, "[host:port]"));
  19329. if (target == NULL && tools == false)
  19330. {
  19331. wchar_t *str;
  19332. // Input a host name
  19333. if (server)
  19334. {
  19335. c->Write(c, _UU("CMD_VPNCMD_HOST_1"));
  19336. }
  19337. else if (client)
  19338. {
  19339. c->Write(c, _UU("CMD_VPNCMD_HOST_2"));
  19340. }
  19341. str = c->ReadLine(c, _UU("CMD_VPNCMD_HOST_3"), true);
  19342. c->Write(c, L"");
  19343. target = CopyUniToStr(str);
  19344. Free(str);
  19345. if (target == NULL)
  19346. {
  19347. // Cancel
  19348. FreeParamValueList(o);
  19349. return ERR_USER_CANCEL;
  19350. }
  19351. if (IsEmptyStr(target))
  19352. {
  19353. Free(target);
  19354. target = CopyStr("localhost");
  19355. }
  19356. }
  19357. else
  19358. {
  19359. // User specifies a host name
  19360. host_inputted = true;
  19361. }
  19362. if (tools == false)
  19363. {
  19364. if (ParseHostPort(target, &hostname, &port, 443) == false)
  19365. {
  19366. c->Write(c, _UU("CMD_MSG_INVALID_HOSTNAME"));
  19367. Free(target);
  19368. FreeParamValueList(o);
  19369. return ERR_INVALID_PARAMETER;
  19370. }
  19371. }
  19372. // Password
  19373. password = GetParamStr(o, "PASSWORD");
  19374. if (password == NULL)
  19375. {
  19376. password = "";
  19377. }
  19378. // Command line
  19379. cmdline = GetParamUniStr(o, "CMD");
  19380. if (server)
  19381. {
  19382. // Process as the server
  19383. char *hub;
  19384. char *adminhub = NULL;
  19385. hub = CopyStr(GetParamStr(o, "HUB"));
  19386. adminhub = GetParamStr(o, "ADMINHUB");
  19387. // Decide the Virtual HUB to be specified in the Virtual HUB management mode
  19388. if (hub == NULL)
  19389. {
  19390. if (host_inputted == false)
  19391. {
  19392. wchar_t *s;
  19393. // If the user does not specify a host name on the command line,
  19394. // get also a Virtual HUB name by displaying the prompt
  19395. c->Write(c, _UU("CMD_VPNCMD_HUB_1"));
  19396. s = c->ReadLine(c, _UU("CMD_VPNCMD_HUB_2"), true);
  19397. hub = CopyUniToStr(s);
  19398. Free(s);
  19399. }
  19400. }
  19401. if (IsEmptyStr(hub))
  19402. {
  19403. Free(hub);
  19404. hub = NULL;
  19405. }
  19406. if (IsEmptyStr(adminhub))
  19407. {
  19408. adminhub = NULL;
  19409. }
  19410. retcode = PsConnect(c, hostname, port, hub, adminhub, cmdline, password);
  19411. Free(hub);
  19412. }
  19413. else if (client)
  19414. {
  19415. // Treated as a client
  19416. Trim(target);
  19417. retcode = PcConnect(c, target, cmdline, password);
  19418. }
  19419. else if (tools)
  19420. {
  19421. // Treated as a VPN Tools
  19422. retcode = PtConnect(c, cmdline);
  19423. }
  19424. Free(hostname);
  19425. Free(target);
  19426. FreeParamValueList(o);
  19427. return retcode;
  19428. }
  19429. // Entry point of vpncmd
  19430. UINT CommandMain(wchar_t *command_line)
  19431. {
  19432. UINT ret = 0;
  19433. wchar_t *infile, *outfile;
  19434. char *a_infile, *a_outfile;
  19435. wchar_t *csvmode;
  19436. wchar_t *programming_mode;
  19437. CONSOLE *c;
  19438. // Validate arguments
  19439. if (command_line == NULL)
  19440. {
  19441. return ERR_INVALID_PARAMETER;
  19442. }
  19443. // Look ahead only items of /in and /out
  19444. infile = ParseCommand(command_line, L"in");
  19445. outfile = ParseCommand(command_line, L"out");
  19446. if (UniIsEmptyStr(infile))
  19447. {
  19448. Free(infile);
  19449. infile = NULL;
  19450. }
  19451. if (UniIsEmptyStr(outfile))
  19452. {
  19453. Free(outfile);
  19454. outfile = NULL;
  19455. }
  19456. a_infile = CopyUniToStr(infile);
  19457. a_outfile = CopyUniToStr(outfile);
  19458. // Allocate the local console
  19459. c = NewLocalConsole(infile, outfile);
  19460. if (c != NULL)
  19461. {
  19462. // Definition of commands of vpncmd
  19463. CMD cmd[] =
  19464. {
  19465. {"vpncmd", VpnCmdProc},
  19466. };
  19467. // Read ahead to check the CSV mode
  19468. csvmode = ParseCommand(command_line, L"csv");
  19469. if(csvmode != NULL)
  19470. {
  19471. Free(csvmode);
  19472. c->ConsoleType = CONSOLE_CSV;
  19473. }
  19474. programming_mode = ParseCommand(command_line, L"programming");
  19475. if (programming_mode != NULL)
  19476. {
  19477. Free(programming_mode);
  19478. c->ProgrammingMode = true;
  19479. }
  19480. if (DispatchNextCmdEx(c, command_line, ">", cmd, sizeof(cmd) / sizeof(cmd[0]), NULL) == false)
  19481. {
  19482. ret = ERR_INVALID_PARAMETER;
  19483. }
  19484. else
  19485. {
  19486. ret = c->RetCode;
  19487. }
  19488. // Release the local console
  19489. c->Free(c);
  19490. }
  19491. else
  19492. {
  19493. Print("Error: Couldn't open local console.\n");
  19494. }
  19495. Free(a_infile);
  19496. Free(a_outfile);
  19497. Free(infile);
  19498. Free(outfile);
  19499. return ret;
  19500. }
  19501. #ifdef OS_WIN32
  19502. // Debug information write mode
  19503. void Win32CmdDebug(bool is_uac)
  19504. {
  19505. wchar_t *dst;
  19506. wchar_t def_filename[MAX_SIZE];
  19507. SYSTEMTIME st;
  19508. InitWinUi(_UU("CMD_DEBUG_SOFTNAME"), NULL, 0);
  19509. UniPrint(_UU("CMD_DEBUG_PRINT"));
  19510. if (MsIsWin2000OrGreater() == false)
  19511. {
  19512. MsgBox(NULL, 0x00000040L, _UU("CMD_DEBUG_NOT_2000"));
  19513. goto LABEL_CLEANUP;
  19514. }
  19515. if ((MsIsVista() == false || is_uac) && MsIsAdmin() == false)
  19516. {
  19517. MsgBox(NULL, 0x00000040L, _UU("CMD_DEBUG_NOT_ADMIN"));
  19518. goto LABEL_CLEANUP;
  19519. }
  19520. if (MsIsVista() && MsIsAdmin() == false)
  19521. {
  19522. void *process_handle = NULL;
  19523. // Launch myself using the UAC
  19524. if (MsExecuteEx2W(MsGetExeFileNameW(), L"/debug_uac", &process_handle, true) == false)
  19525. {
  19526. MsgBox(NULL, 0x00000030L, _UU("CMD_DEBUG_UAC_FAILED"));
  19527. return;
  19528. }
  19529. MsCloseHandle(process_handle);
  19530. goto LABEL_CLEANUP;
  19531. }
  19532. LocalTime(&st);
  19533. UniFormat(def_filename, sizeof(def_filename), L"vpn_debuginfo_%04u%02u%02u_%02u%02u%02u.zip",
  19534. st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
  19535. // Specify the destination
  19536. dst = SaveDlg(NULL, _UU("DLG_ZIP_FILER"), _UU("CMD_DEBUG_SAVE_TITLE"), def_filename, L".zip");
  19537. if (dst != NULL)
  19538. {
  19539. if (MsSaveSystemInfo(dst) == false)
  19540. {
  19541. // Failure
  19542. MsgBoxEx(NULL, 0x00000030L, _UU("CMD_DEBUG_NG"), dst);
  19543. }
  19544. else
  19545. {
  19546. // Success
  19547. MsgBoxEx(NULL, 0x00000040L, _UU("CMD_DEBUG_OK"), dst);
  19548. }
  19549. Free(dst);
  19550. }
  19551. LABEL_CLEANUP:
  19552. FreeWinUi();
  19553. }
  19554. #endif // OS_WIN32
  19555. // Developed by SoftEther VPN Project at University of Tsukuba in Japan.
  19556. // Department of Computer Science has dozens of overly-enthusiastic geeks.
  19557. // Join us: http://www.tsukuba.ac.jp/english/admission/