What is the ruling on working to restore network equipment (routers) for a company that uses them for the lottery?
Question

I worked under a telecom contractor company Say, "Company A". "A" got a contract from a big telecom company say, "Company B". The contract is "B" will provide network equipment (routers) to different stores of "Company C". "C" will use these routers to connect lottery equipment. My job under company "A" is to configure these routers as a network engineer. Though Company “A” hired me for this job only, however, when I joined I had been given other responsibilies (not related to company C; and not related to lottery) as well besides configuring router for Company “C”. My question is:
1a. Is this Job/income permissible for me?
1b. When I started the job I consulted with a local imam; He said since I have no other income and I am obliged to spend for my family, so I can do the job while searching for alternative. Now after a year I stopped doing the job and looking for another opportunity. My question is, if my income (salary) is considered not permissible, then what I need to do with the money that left after consumption. What about the amount that I already consumed to maintain my family?
Praise be to Allah.Firstly:
Prohibition on helping with gambling
It is haraam to help with gambling such as lotteries, and that includes working on configuring routers that the company uses, because Allah, may He be exalted, says (interpretation of the meaning):
{And cooperate in righteousness and piety, but do not cooperate in sin and transgression. And fear Allah; indeed, Allah is severe in penalty} [al-Maa’idah 5:2].
And the Prophet (blessings and peace of Allah be upon him) said: “Whoever calls people to misguidance will have a burden of sin like that of those who follow him, without that detracting from their burdens in the slightest.” Narrated by Muslim in his Saheeh (4831).
If you are able to avoid this work, and continue with your other responsibilities, there is nothing wrong with you staying with that company. But if you cannot avoid what is haraam, then you must leave this job, and whoever gives up something for the sake of Allah, Allah will compensate him with something better.
Secondly:
Money earned by helping with the lottery
With regard to the money that you earned when you were unaware of the prohibition on this work, or when you followed a fatwa issued by one who granted you a concession to remain in that job until you find another job, there is nothing wrong with you making use of it, even if some of it is in your possession, because Allah, may He be exalted, says with regard to riba (usury, interest), which is one of the worst of prohibited things (interpretation of the meaning):
{Allah has permitted trade and has forbidden interest. So whoever has received an admonition from his Lord and desists may have what is past} [al-Baqarah 2:275].
Shaykh al-‘Uthaymeen (may Allah have mercy on him) said: If he did not know that this is haraam, he may keep what he received and he does not have to do anything. Or if he was deceived by a fatwa from a scholar saying that it was not haraam, he does not have to give anything, because Allah, may He be exalted, says (interpretation of the meaning):
{Allah has permitted trade and has forbidden interest. So whoever has received an admonition from his Lord and desists may have what is past} [al-Baqarah 2:275]".(Al-Liqa’ ash-Shahri  67/19).
As for the money that you received after finding out that it is haraam to remain in this job: regarding what you spend of it, you do not have to do anything regarding it except to repent. Regarding what remains with you of it, you must get rid of the haraam portion of it, by giving it to the poor and the like.
If your permissible work takes up half of the day or half of the month, and your unlawful work takes up the other half, then what is prohibited is half of your salary.
But if you need the money that you have, meaning that if you give it in charity, you will not be able to spend on your family’s maintenance, then there is no blame on you if you make use of it. So you should take as much of it as you need, and give the rest in charity.
For more information, please see the answers to questions no. 103918 and 78289 .
We ask Allah to provide for you from His bounty, and to make you independent of means through that which is halaal and good.
And Allah knows best.