agent_conf.sh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. #!/bin/bash
  2. #
  3. # OGP - Open Game Panel
  4. # Copyright (C) Copyright (C) 2008 - 2013 The OGP Development Team
  5. #
  6. # http://www.opengamepanel.org/
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. #
  22. ####################
  23. # FUNCTIONs #
  24. ####################
  25. function indexOf(){
  26. # $1 = search string
  27. # $2 = string or char to find
  28. # Returns -1 if not found
  29. x="${1%%$2*}"
  30. [[ $x = $1 ]] && echo -1 || echo ${#x}
  31. }
  32. #####################
  33. # CODE ##########
  34. #####################
  35. if [ $EUID -ne 0 -a "$(uname -o)" != "Cygwin" ]; then
  36. echo "This script must be run as root" 1>&2
  37. exit 1
  38. fi
  39. usage()
  40. {
  41. cat << EOF
  42. Usage: $0 option
  43. OPTIONS:
  44. -s password Set the password for the agent's user (Linux)
  45. -p password Set the password for cyg_server user (Windows)
  46. -u ogpuser Set the username of the ogp user
  47. EOF
  48. }
  49. while getopts "hs:p:u" OPTION
  50. do
  51. case $OPTION in
  52. s)
  53. sudo_password=$OPTARG
  54. ;;
  55. p)
  56. cs_psw=$OPTARG
  57. ;;
  58. u)
  59. agent_user=$OPTARG
  60. ;;
  61. ?)
  62. exit
  63. ;;
  64. esac
  65. done
  66. if [ -z $1 ]
  67. then
  68. usage
  69. exit
  70. fi
  71. if [ "$(uname -o)" == "Cygwin" ]; then
  72. if [ -z $cs_psw ]
  73. then
  74. echo "Must use -p argument instead of -s."
  75. exit
  76. fi
  77. else
  78. if [ -z $sudo_password ]
  79. then
  80. echo "Must use -s argument instead of -p."
  81. exit
  82. fi
  83. fi
  84. readonly DEFAULT_PORT=12679
  85. readonly DEFAULT_IP=0.0.0.0
  86. readonly DEFAULT_FTP_PORT=21
  87. readonly DEFAULT_FTP_PASV_RANGE=40000:50000
  88. readonly AGENT_VERSION='v1.4'
  89. failed()
  90. {
  91. echo "ERROR: ${1}"
  92. exit 1
  93. }
  94. agent_home="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  95. cfgfile=${agent_home}/Cfg/Config.pm
  96. prefsfile=${agent_home}/Cfg/Preferences.pm
  97. bashprefsfile=${agent_home}/Cfg/bash_prefs.cfg
  98. overwrite_config=1
  99. if [ -e ${cfgfile} ]; then
  100. while [ 1 ]
  101. do
  102. echo "Overwrite old configuration?"
  103. echo -n "(yes/no) [Default yes]: "
  104. read octmp
  105. if [ "$octmp" == "yes" -o -z "$octmp" ]
  106. then
  107. break
  108. elif [ "$octmp" == "no" ]
  109. then
  110. overwrite_config=0
  111. break
  112. else
  113. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  114. fi
  115. done
  116. fi
  117. if [ "X${overwrite_config}" == "X1" ]
  118. then
  119. if [ -z "$sudo_password" ]; then
  120. if [ -f "$cfgfile" ]; then
  121. sudo_password=`awk '/sudo_password/{print $3}' $cfgfile|sed -e "s#\('\)\(.*\)\(',\)#\2#"`
  122. fi
  123. fi
  124. echo "#######################################################################"
  125. echo ""
  126. echo "OGP agent uses basic encryption to prevent unauthorized users from connecting"
  127. echo "Enter a string of alpha-numeric characters for example 'abcd12345'"
  128. echo "**** NOTE - Use the same key in your Open Game Panel webpage config file - they must match *****"
  129. echo ""
  130. while [ -z "${key}" ]
  131. do
  132. echo -n "Set encryption key: "
  133. read key
  134. done
  135. echo
  136. echo "Set the listen port for the agent. The default should be fine for everyone."
  137. echo "However, if you want to change it that can be done here, otherwise just press Enter."
  138. echo -n "Set listen port [Default ${DEFAULT_PORT}]: "
  139. read port
  140. if [ -z "${port}" ]
  141. then
  142. port=$DEFAULT_PORT
  143. fi
  144. echo
  145. echo "Set the listen IP for the agent."
  146. echo "Use ${DEFAULT_IP} to bind on all interfaces."
  147. echo -n "Set listen IP [Default ${DEFAULT_IP}]: "
  148. read ip
  149. if [ -z "${ip}" ]
  150. then
  151. ip=$DEFAULT_IP
  152. fi
  153. while [ 1 ]
  154. do
  155. echo
  156. echo "For some games the OGP panel is using Steam client."
  157. echo "This client has its own license that you need to agree before continuing."
  158. echo "This agreement is available at http://store.steampowered.com/subscriber_agreement/"
  159. echo;
  160. echo "Do you accept the terms of Steam(tm) Subscriber Agreement?"
  161. echo -n "(Accept|Reject): "
  162. read steam_license
  163. if [ "$steam_license" == "Accept" -o "$steam_license" == "Reject" ]
  164. then
  165. break;
  166. fi
  167. echo "You need to type either 'Accept' or 'Reject'."
  168. done
  169. echo "Writing Config file - $cfgfile"
  170. echo "%Cfg::Config = (
  171. logfile => '${agent_home}/ogp_agent.log',
  172. listen_port => '${port}',
  173. listen_ip => '${ip}',
  174. version => '${AGENT_VERSION}',
  175. key => '${key}',
  176. steam_license => '${steam_license}',
  177. sudo_password => '${sudo_password}',
  178. );" > $cfgfile
  179. if [ $? != 0 ]
  180. then
  181. failed "Failed to write config file."
  182. else
  183. chmod 600 ${cfgfile} || failed "Failed to chmod ${cfgfile} to 600."
  184. fi
  185. echo;
  186. while [ 1 ]
  187. do
  188. echo "The agent should be updated when the service is restarted or started?"
  189. echo -n "(yes|no) [Default yes]: "
  190. read auto_update
  191. if [ "${auto_update}" == "yes" -o "${auto_update}" == "no" -o -z "${auto_update}" ]
  192. then
  193. if [ "${auto_update}" == "yes" ]
  194. then
  195. autoUpdate=1
  196. elif [ -z "${auto_update}" ]
  197. then
  198. autoUpdate=1
  199. else
  200. autoUpdate=0
  201. fi
  202. break;
  203. fi
  204. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  205. done
  206. echo;
  207. while [ 1 ]
  208. do
  209. echo "The agent should backup the server log files in the game server directory?"
  210. echo -n "(yes|no) [Default yes]: "
  211. read log_local_copy
  212. if [ "${log_local_copy}" == "yes" -o "${log_local_copy}" == "no" -o -z "${log_local_copy}" ]
  213. then
  214. if [ "${log_local_copy}" == "yes" ]
  215. then
  216. logLocalCopy=1
  217. elif [ -z "${log_local_copy}" ]
  218. then
  219. logLocalCopy=1
  220. else
  221. logLocalCopy=0
  222. fi
  223. break;
  224. fi
  225. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  226. done
  227. echo;
  228. echo "After how many days should be deleted the old backups of server's logs?"
  229. echo -n "[Default 30]: "
  230. read delete_logs_after
  231. case ${delete_logs_after} in
  232. ''|*[!0-9]*) deleteLogsAfter=30 ;;
  233. *) deleteLogsAfter=${delete_logs_after} ;;
  234. esac
  235. echo;
  236. while [ 1 ]
  237. do
  238. echo "The agent should automatically restart game servers if they crash?"
  239. echo -n "(yes|no) [Default yes]: "
  240. read auto_restart
  241. if [ "${auto_restart}" == "yes" -o "${auto_restart}" == "no" -o -z "${auto_restart}" ]
  242. then
  243. if [ "${auto_restart}" == "yes" ]
  244. then
  245. autoRestart=1
  246. elif [ -z "${auto_restart}" ]
  247. then
  248. autoRestart=1
  249. else
  250. autoRestart=0
  251. fi
  252. break;
  253. fi
  254. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  255. done
  256. echo;
  257. while [ 1 ]
  258. do
  259. echo "Should Open Game Panel create and manage FTP accounts?"
  260. echo -n "(yes|no) [Default yes]: "
  261. read manage_ftp
  262. if [ "${manage_ftp}" == "yes" -o "${manage_ftp}" == "no" -o -z "${manage_ftp}" ]
  263. then
  264. if [ "${manage_ftp}" == "yes" ]
  265. then
  266. ogpManagesFTP=1
  267. elif [ -z "${manage_ftp}" ]
  268. then
  269. ogpManagesFTP=1
  270. else
  271. ogpManagesFTP=0
  272. fi
  273. break;
  274. fi
  275. echo "You need to type 'yes', 'no' or leave empty for default value [yes]."
  276. done
  277. echo;
  278. # Only ask these install questions if users want OGP to manage FTP accounts
  279. if [ "$ogpManagesFTP" == "1" ]
  280. then
  281. if [ "$(uname -o)" != "Cygwin" ]; then
  282. while [ 1 ]
  283. do
  284. echo "If you are running ISPConfig 3 in this machine the agent"
  285. echo "can use it to create FTP accounts instead of using Pure-FTPd."
  286. echo "Would you like to configure this agent to use the API of ISPConfig 3?"
  287. echo -n "(yes|no) [Default no]: "
  288. read IspConfig
  289. if [ "${IspConfig}" == "yes" -o "${IspConfig}" == "no" -o -z "${IspConfig}" ]
  290. then
  291. if [ "${IspConfig}" == "yes" ]
  292. then
  293. ftpMethod="IspConfig"
  294. else
  295. IspConfig="no"
  296. fi
  297. break;
  298. fi
  299. echo "You need to type 'yes', 'no' or leave empty for default value [no]."
  300. done
  301. if [ "${IspConfig}" == "yes" ]
  302. then
  303. while [ 1 ]
  304. do
  305. echo "Do you use HTTPS to access to your ISPConfig 3 Panel?"
  306. echo -n "(yes|no) [Default no]: "
  307. read https
  308. if [ "${https}" == "yes" -o "${https}" == "no" -o -z "${https}" ]
  309. then
  310. if [ "${https}" == "yes" ]
  311. then
  312. secure="s"
  313. else
  314. secure=""
  315. fi
  316. break;
  317. fi
  318. echo "You need to type 'yes', 'no' or leave empty for default value [no]."
  319. done
  320. echo -n "What port do you use to connect to your ISPConfig 3 Panel? [Default 8080]: "
  321. read setport
  322. case ${setport} in
  323. ''|*[!0-9]*) port=8080 ;;
  324. *) port=${setport} ;;
  325. esac
  326. echo -n "Enter an user name to sing in remotelly (Remote user): "
  327. read remote_login_username
  328. echo -n "Enter password (Remote user): "
  329. read remote_login_password
  330. echo -e "<?php\n\$username = '${remote_login_username}';" > ${agent_home}/IspConfig/soap_config.php
  331. echo "\$password = '${remote_login_password}';" >> ${agent_home}/IspConfig/soap_config.php
  332. echo "\$soap_location = 'http${secure}://127.0.0.1:${port}/remote/index.php';" >> ${agent_home}/IspConfig/soap_config.php
  333. echo -e "\$soap_uri = 'http${secure}://127.0.0.1:${port}/remote/';\n?>" >> ${agent_home}/IspConfig/soap_config.php
  334. else
  335. while [ 1 ]
  336. do
  337. echo;
  338. echo "If you have installed the Easy Hosting Control Panel (EHCP - www.ehcpforce.tk),"
  339. echo "the agent can use it to create FTP accounts instead of using Pure-FTPd."
  340. echo "Would you like to configure this agent to use the API of EHCP?"
  341. echo -n "(yes|no) [Default no]: "
  342. read ehcp
  343. if [ "${ehcp}" == "yes" -o "${ehcp}" == "no" -o -z "${ehcp}" ]
  344. then
  345. if [ "${ehcp}" == "yes" ]
  346. then
  347. ftpMethod="EHCP"
  348. fi
  349. break;
  350. fi
  351. echo "You need to type 'yes', 'no' or leave empty for default value [no]."
  352. done
  353. if [ "${ehcp}" == "yes" ]
  354. then
  355. echo "Please enter the MySQL database password for the ehcp user"
  356. echo -n "(created during the install of EHCP): "
  357. read ehcpDB
  358. ehcpConf=${agent_home}/EHCP/config.php
  359. sed -i "s/changeme/${ehcpDB}/" $ehcpConf
  360. else
  361. while [ 1 ]
  362. do
  363. echo;
  364. echo "The agent can use ProFTPd to create FTP accounts."
  365. echo "Would you like to configure this agent to use the ProFTPd?"
  366. echo -n "(yes|no) [Default no]: "
  367. read proftpd
  368. if [ "${proftpd}" == "yes" -o "${proftpd}" == "no" -o -z "${proftpd}" ]
  369. then
  370. if [ "${proftpd}" == "yes" ]
  371. then
  372. ftpMethod="proftpd"
  373. fi
  374. break;
  375. fi
  376. echo "You need to type 'yes', 'no' or leave empty for default value [no]."
  377. done
  378. if [ "${proftpd}" == "yes" ]
  379. then
  380. echo "Please enter the path for proFTPd configuration file"
  381. echo -n "[Default /etc/proftpd/proftpd.conf]: "
  382. read proFTPdConfFile
  383. if [ -z $proFTPdConfFile ]
  384. then
  385. proFTPdConfFile="/etc/proftpd/proftpd.conf"
  386. if [ ! -e "$proFTPdConfFile" ]; then
  387. proFTPdConfFile="/etc/proftpd.conf"
  388. fi
  389. fi
  390. proFTPdConfPath=$(dirname ${proFTPdConfFile})
  391. while [ 1 ]
  392. do
  393. if [ ! -e $proFTPdConfFile ]
  394. then
  395. echo "The file ${proFTPdConfFile} does not exists,"
  396. echo "what you want to do, reenter it or ignore and continue?"
  397. echo "If your answer is 'ignore' is meant that you will install proFTPd later."
  398. echo -n "(reenter|ignore): "
  399. read answer
  400. if [ "${answer}" == "reenter" -o "${answer}" == "ignore" ]
  401. then
  402. if [ "${answer}" == "reenter" ]
  403. then
  404. echo "Reenter proFTPd's configuration file path:"
  405. read proFTPdConfFile
  406. continue
  407. elif [ "${answer}" == "ignore" ]
  408. then
  409. echo "You will need to append this to ${proFTPdConfFile} once you've installed proftpd:"
  410. bold=`tput bold`
  411. normal=`tput sgr0`
  412. echo -e "\n\n${bold}RequireValidShell off\nAuthUserFile ${proFTPdConfPath}/ftpd.passwd\nAuthGroupFile ${proFTPdConfPath}/ftpd.group${normal}\n\n"
  413. break
  414. fi
  415. fi
  416. echo "You need to type 'reenter' or 'ignore'."
  417. else
  418. if egrep -iq "LoadModule\s*mod_auth_file.c" ${proFTPdConfFile}
  419. then
  420. sed -i "s/\s*#\s*LoadModule\s*mod_auth_file.c/LoadModule mod_auth_file.c/g" ${proFTPdConfFile}
  421. else
  422. echo -e "LoadModule mod_auth_file.c" >> ${proFTPdConfFile}
  423. fi
  424. if egrep -iq "^\s*AuthOrder.*" ${proFTPdConfFile}
  425. then
  426. if egrep -iq "^\s*AuthOrder.*mod_auth_file.c" ${proFTPdConfFile}
  427. then
  428. false
  429. else
  430. sed -ri "s/(^\s*AuthOrder.*)/\1 mod_auth_file.c/g" ${proFTPdConfFile}
  431. fi
  432. else
  433. echo -e "AuthOrder mod_auth_file.c" >> ${proFTPdConfFile}
  434. fi
  435. if egrep -iq "RequireValidShell.*" ${proFTPdConfFile}
  436. then
  437. sed -i "s#RequireValidShell.*#RequireValidShell off#g" ${proFTPdConfFile}
  438. else
  439. echo -e "RequireValidShell off" >> ${proFTPdConfFile}
  440. fi
  441. if egrep -iq "AuthUserFile.*" ${proFTPdConfFile}
  442. then
  443. sed -i "s#AuthUserFile.*#AuthUserFile ${proFTPdConfPath}/ftpd.passwd#g" ${proFTPdConfFile}
  444. else
  445. echo -e "AuthUserFile "${proFTPdConfPath}"/ftpd.passwd" >> ${proFTPdConfFile}
  446. fi
  447. if egrep -iq "AuthGroupFile.*" ${proFTPdConfFile}
  448. then
  449. sed -i "s#AuthGroupFile.*#AuthGroupFile ${proFTPdConfPath}/ftpd.group#g" ${proFTPdConfFile}
  450. else
  451. echo -e "AuthGroupFile "${proFTPdConfPath}"/ftpd.group" >> ${proFTPdConfFile}
  452. fi
  453. # Allow global overwrite (http://opengamepanel.org/forum/viewthread.php?thread_id=5202)
  454. if egrep -iq "AllowOverwrite.*" ${proFTPdConfFile}
  455. then
  456. sed -i "s#AllowOverwrite.*#AllowOverwrite yes#g" ${proFTPdConfFile}
  457. else
  458. echo -e "<Global>\nAllowOverwrite yes\n</Global>" >> ${proFTPdConfFile}
  459. fi
  460. if [ ! -e "${proFTPdConfPath}/ftpd.group" ]
  461. then
  462. touch ${proFTPdConfPath}/ftpd.group
  463. fi
  464. if [ ! -e "${proFTPdConfPath}/ftpd.passwd" ]
  465. then
  466. touch ${proFTPdConfPath}/ftpd.passwd
  467. fi
  468. ftpd_user=$(grep -oP '^User\s+\K.+' ${proFTPdConfFile})
  469. ftpd_group=$(grep -oP '^Group\s+\K.+' ${proFTPdConfFile})
  470. if [ -z "$agent_user" ]; then
  471. agent_user=$(grep -oP 'agent_user=\K.+' /etc/init.d/ogp_agent)
  472. fi
  473. if [ ! -z "$ftpd_user" ] && [ ! -z "$ftpd_group" ] && [ ! -z "$agent_user" ]
  474. then
  475. if [ "$(groups $agent_user|grep $ftpd_group)" == "" ]
  476. then
  477. usermod -aG $ftpd_group $agent_user
  478. fi
  479. if [ -e "${proFTPdConfPath}/ftpd.passwd" -a -e "${proFTPdConfPath}/ftpd.group" ]
  480. then
  481. chmod 640 ${proFTPdConfPath}/ftpd.*
  482. chown -f $ftpd_user:$ftpd_group ${proFTPdConfPath}/ftpd.*
  483. fi
  484. fi
  485. break
  486. fi
  487. done
  488. if [ -e "/etc/init.d/proftpd" ]
  489. then
  490. /etc/init.d/proftpd restart
  491. else
  492. echo "If proftpd is running, to apply the changes, you must restart the service."
  493. fi
  494. else
  495. ftpMethod="PureFTPd"
  496. fi
  497. fi
  498. fi
  499. else
  500. if uname -a|grep -q "x86_64"
  501. then
  502. FZ="yes"
  503. else
  504. while [ 1 ]
  505. do
  506. echo;
  507. echo "If you have installed the FileZilla Server,"
  508. echo "the agent can use it to create FTP accounts instead of using Pure-FTPd."
  509. echo "Would you like to configure this agent to use it?"
  510. echo -n "(yes|no) [Default no]: "
  511. read FZ
  512. if [ "${FZ}" == "yes" -o "${FZ}" == "no" -o -z "${FZ}" ]
  513. then
  514. break;
  515. fi
  516. echo "You need to type 'yes', 'no' or leave empty for default value [no].";
  517. done
  518. fi
  519. if [ "${FZ}" == "yes" ]; then
  520. ftpMethod="FZ"
  521. PF=$(cmd /Q /C echo %PROGRAMFILES\(X86\)% | sed 's/\r$//')
  522. if [ "X${PF}" == "X" ];then PF=$(cmd /Q /C echo %PROGRAMFILES% | sed 's/\r$//'); fi
  523. echo;
  524. echo "Please enter the path for FileZilla server executable file"
  525. echo -n "[Default ${PF}\\FileZilla Server\\FileZilla server.exe]: "
  526. read -r FZ_EXE
  527. if [ -z "${FZ_EXE}" ]
  528. then
  529. FZ_EXE="${PF}\\FileZilla Server\\FileZilla server.exe"
  530. fi
  531. echo;
  532. echo "Please enter the path for FileZilla server xml file"
  533. echo -n "[Default ${PF}\\FileZilla Server\\FileZilla Server.xml]: "
  534. read -r FZ_XML
  535. if [ -z "${FZ_XML}" ]
  536. then
  537. FZ_XML="${PF}\\FileZilla Server\\FileZilla server.xml"
  538. fi
  539. FZ_EXE=$(cygpath -u "$FZ_EXE")
  540. FZ_XML=$(cygpath -u "$FZ_XML")
  541. FZconf=${agent_home}/Cfg/FileZilla.pm
  542. echo -e "%Cfg::FileZilla = (\n\tfz_exe => '${FZ_EXE}',\n\tfz_xml => '${FZ_XML}'\n);" > ${FZconf}
  543. if [ $? != 0 ]
  544. then
  545. failed "Failed to write FileZilla configuration file."
  546. fi
  547. if [ ! -z "$cs_psw" ]; then
  548. UD=$(cmd /Q /C echo %USERDOMAIN% | sed 's/\r$//')
  549. net stop "FileZilla Server"
  550. sc config "FileZilla Server" obj= "${UD}\cyg_server" password= "$cs_psw" type= own
  551. net start "FileZilla Server"
  552. fi
  553. else
  554. if uname -a|grep -qv "x86_64"
  555. then
  556. ftpMethod="PureFTPd"
  557. echo;
  558. echo "Set the listen IP for the PureFTPd."
  559. echo "Default is (${DEFAULT_IP}) to bind on all interfaces."
  560. echo -n "Set listen IP [Default ${DEFAULT_IP}]: "
  561. read ftp_ip
  562. if [ -z "${ftp_ip}" ]
  563. then
  564. ftp_ip=$DEFAULT_IP
  565. fi
  566. echo
  567. echo "Set the listen port for PureFTPd. The default should be fine for everyone."
  568. echo "However, if you want to change it that can be done here, otherwise just press Enter."
  569. echo -n "Set listen port [Default ${DEFAULT_FTP_PORT}]: "
  570. read port
  571. if [ -z "${ftp_port}" ]
  572. then
  573. ftp_port=$DEFAULT_FTP_PORT
  574. fi
  575. echo
  576. echo "Passive-mode downloads."
  577. echo "This is especially useful if the server is behind a firewall."
  578. echo -n "Use only ports in the range?(yes|no)[Default no]: "
  579. read passive_ftp
  580. if [ -z "${passive_ftp}" -o "${passive_ftp}" != "yes" ]
  581. then
  582. ftp_pasv_range=""
  583. else
  584. echo "Enter passive ports range separated by colon (<first port>:<last port>)."
  585. echo -n "[Default ${DEFAULT_FTP_PASV_RANGE}]: "
  586. read ftp_pasv_range
  587. if [ -z "${ftp_pasv_range}" ]
  588. then
  589. ftp_pasv_range=$DEFAULT_FTP_PASV_RANGE
  590. fi
  591. fi
  592. fi
  593. fi
  594. fi
  595. fi
  596. if [ "${ftpMethod}" == "PureFTPd" ]
  597. then
  598. run_pureftpd=1
  599. else
  600. run_pureftpd=0
  601. fi
  602. echo "Writing Preferences file - $prefsfile"
  603. prefs="%Cfg::Preferences = (\n"
  604. prefs="${prefs}\tscreen_log_local => '${logLocalCopy}',\n"
  605. prefs="${prefs}\tdelete_logs_after => '${deleteLogsAfter}',\n"
  606. prefs="${prefs}\togp_manages_ftp => '${ogpManagesFTP}',\n"
  607. prefs="${prefs}\tftp_method => '${ftpMethod}',\n"
  608. prefs="${prefs}\togp_autorestart_server => '${autoRestart}',\n"
  609. if [ "X${proftpd}" == "Xyes" ]
  610. then
  611. prefs="${prefs}\tproftpd_conf_path => '${proFTPdConfPath}'\n"
  612. fi
  613. prefs="${prefs});"
  614. echo -e $prefs > $prefsfile
  615. if [ $? != 0 ]
  616. then
  617. failed "Failed to write preferences file."
  618. fi
  619. echo "Writing bash script preferences file - $bashprefsfile"
  620. echo -e "agent_auto_update=${autoUpdate}\nrun_pureftpd=${run_pureftpd}\nftp_port=${ftp_port}\nftp_ip=${ftp_ip}\nftp_pasv_range=${ftp_pasv_range}" > $bashprefsfile
  621. if [ $? != 0 ]
  622. then
  623. failed "Failed to write MISC configuration file used by bash scripts."
  624. fi
  625. fi